Fix crash writing on diconnected sockets