Address concurrent client variable modification

Currently we aren't protecting all the needed client
variables against concurrent modification, which makes
it hard to use the client when it is shared among
threads.

To be better at this use locks in the appropriate places
where those variables are mutated and ensure they are
not mutated (or iterated while mutated).