it looks generally thread-safe to me, apart from the possibility of simultaneous invocations of `connect`; am removing warnings in updated pull request