adding locking to connection thread