Fix race that could happen when a connect attempt was not finished yet a...

...nd another write was triggered and the connect finished in between the write.

Related to BZ-434064