Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloseHandler not called #325

Closed
alexppxela opened this issue Jan 10, 2018 · 4 comments
Closed

CloseHandler not called #325

alexppxela opened this issue Jan 10, 2018 · 4 comments

Comments

@alexppxela
Copy link

Hi,

My server is reading data looping on ws.NextReader().

The client opens the websocket like this:
conn, rsp, err := websocket.DefaultDialer.Dial(u.String(), nil).
When it closes the websocket conn.Close(), the server is not correctly notified.

ws.NextReader() returns:

  • err: close 1006 (abnormal closure): unexpected EOF

But CloseHandler is not called.

@garyburd
Copy link
Contributor

garyburd commented Jan 10, 2018

This is expected. The close handler is called when a close message is received from the peer. The peer did not send a close message.

What does the application do in the close handler?

Most applications should handle close messages as part of their normal error handling. Applications should only set a close handler when the application must perform some action before sending a close message back to the peer.

@alexppxela
Copy link
Author

I was confused because I thought that close handler was called whatever the cause of close.
My application is a gateway between a client and a server, so when my client websocket is closed, I close the connection to the server. I use close handler as a notification of close event instead of a last action before sending the frame back to peer.
Thanks for your answer.

@garyburd
Copy link
Contributor

If you are communicating with the server using the websocket protocol, then you may find this code to be helpful.

@alexppxela
Copy link
Author

alexppxela commented Jan 10, 2018

Great helpful code, thanks.
Unfortunately, I do not use websocket to server.

@gorilla gorilla locked and limited conversation to collaborators Aug 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants