renamed onConnectionClose to beforeClose, and call it before message.close in closeMessage()