Fix a "race condition" resulting in bugs when opening a connection under heavy load

See https://github.com/deployd/deployd/issues/453