-
Notifications
You must be signed in to change notification settings - Fork 25
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
Sample server crashes on socket close #44
Comments
How did you "stop the client"? With Ctrl+C? Did you do The problem in this case is how the library treats closed sockets that haven't given a Close opcode which is currently with an IOError. To get around it you'd do this: try:
let (opcode, data) = await ws.readData()
echo "(opcode: ", opcode, ", data: ", data, ")"
except IOError, ProtocolError:
ws.sock.close()
echo "closing websocket because of error: ", getCurrentExceptionMsg() Or this: let (opcode, data) =
try:
await ws.readData()
except:
ws.sock.close()
(Opcode.Close, "")
echo "(opcode: ", opcode, ", data: ", data, ")" But the question remains if the library should either:
If we're gonna keep exceptions which we probably are, I prefer the last one as using IOError everywhere is probably not a good idea |
Yes, I stop the client with Ctrl+C, which is not a valid socket close event. I think, however, the server should be tolerant to that, so a fix in the sample server code will be enough to get rid of the confusion. As a workaround, I wrapped my code in a try block, but your solutions are cleaner, I especially like the second one. On a general note, maybe a switch from nil- and exception-based flow to using options will make the lib interface better? |
websocket.nim version: 0.3.3
Nim version: 0.18.0, devel
Create a server and client from the docs samples:
Compile and run the server and client.
Observe as they exchange data.
Stop the client.
Expected behavior: the server continues running
Actual behavior: the server craches with this trace:
The text was updated successfully, but these errors were encountered: