SetReadDeadline - Chat example (remove idle clients) #961
-
Is there an existing issue for this?
Current BehaviorI used chat example to modify some code, added clients map and send chan. The example makes sense that after pongWait the next reads return err and cause defer to be called thus calling
Expected BehaviorLet's say app user exits, and pong never comes back (thus no next read)... that means the socket is still opened (kind of blocked now but still open)? That socket/connection should be deleted for good after ReadDeadline, it's not. How can I make defer work (that will call Steps To ReproduceNo response Anything else?No response |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
The code in
We cannot determine why this is happening because you don't show the code that manages the collection of |
Beta Was this translation helpful? Give feedback.
-
@hulkingshtick thx for response, my code assumes it's the same as in the chat example. |
Beta Was this translation helpful? Give feedback.
-
I edited my previous comment to be more accurate. What specifically is the scenario where one of those conditions will not be true, but the peer is gone? The hub code in your application is not the same as the hub code in the application. Perhaps you have a bug there. |
Beta Was this translation helpful? Give feedback.
-
@garyburd @hulkingshtick thx, just re-read what you wrote, so you're saying ReadJSON will return err itself without client sending anything? It's just the comment explaining the function says otherwise ("all future reads will return an error"), that why I'm confused I guess:
based on the comment, in case someone's phone battery dies or client network doesn't send a websocket close(), then ReadJSON won't return |
Beta Was this translation helpful? Give feedback.
-
@garyburd @hulkingshtick would appreciate if you could confirm this "in case someone's phone battery dies or client network doesn't send a websocket close(), then ReadJSON won't return err at all even after ReadDeadline bcz a read never came through" |
Beta Was this translation helpful? Give feedback.
-
@garyburd @hulkingshtick I think I found the code in
which means indeed like you said, ReadJSON will return err after
So maybe making ReadJSON comment more clear about err being returned after |
Beta Was this translation helpful? Give feedback.
-
In the Go, a read deadline in the context of network connections is a time limit set on reading from a network connection. The deadline specifies how long the program will wait for data to be received before giving up and returning an error. |
Beta Was this translation helpful? Give feedback.
-
@hulkingshtick ahh see it's an internal go pkg doing the work, then chat example takes my concern into account... Thx for clarifying that |
Beta Was this translation helpful? Give feedback.
In the Go, a read deadline in the context of network connections is a time limit set on reading from a network connection. The deadline specifies how long the program will wait for data to be received before giving up and returning an error.