Locking to avoid to send messages to a closed connection