Fix deadlocking of socket close
Fix deadlocking of socket close

Found out that the deadlocking occured when trying to close the socket when
it was opening. By checking if this is the case (and waiting until it's no longer the case)
we prevent the deadlock from happening.

CURA-2158

onitake/Uranium,onitake/Uranium