No it’s all several connections (and disconnections) from the same client. But what you said have given me an idea. I’ll try using semaphores to protect the sensitive parts of the connection and disconnection code.
Discussion
This worked by the way. I used it to lock access to the bare metal connection and disconnection code so it doesn’t overlap.