Synchronize interaction with the connection store

On JRuby this operation on the connection store hash is not thread safe
and results in race conditions.

Fixes #597