avoid writing to socket if it's already closed