Fix issue with writing to destroyed sockets