Only initiate the WebSocket closing handshake on the client

#3342
Revert "Stop processing messages before ending the WebSocketFunc Task"

This reverts commit 654bfb4198c7f20c49c068335c29d47c5011cb97.