-
Notifications
You must be signed in to change notification settings - Fork 221
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
How to handle ws::ErrorKind::Queue? #59
Comments
In order to avoid overfilling the queue, you need to set the queue size high enough. In this case, you need Settings::max_connections. The event queue is configured to be 5 times the number of allowed connections. The default is 100, so 500 events at a time. You can increase the number of max connections up to The bench-server example shows how to increase the maximum number of allowed connections. In that example, max_connections is set to 10,000, which gives a queue size of 50,000. In my experience 10_000 is a nice number for a production environment, but you can do higher if you need to. |
Thanks Jason! That totally makes sense - I guess what I'm asking for here is instead of making the queue size "large enough hopefully" is there some sort of feedback mechanism I can get from the sender that tells me when the queue's about to be full so I can try again later? Something like an EAGAIN? |
Simply encountering a full queue shouldn't bring down a connection. The queue error exists to inform the caller that the queue is full, so then they can try the operation again later. Sleeping or blocking or trying to schedule a timeout all won't help because to consume events, we need to return to the event loop immediately. Luckily, this should never happen if Anyway, it was not intended behavior that a queue error should result in a connection disconnecting, so this is a bug. The fix I propose is to delegate handling queue errors to handlers and also add a setting to allow people to just increase the per-connection queue size without needing to accept more connections. You should be able to do something like You can handle the queue error yourself with something like this even now:
But I did test this out and the connection is disconnected because of the queue failure at another point, which defect the new changes will fix. I noticed in your code that it's the It's up to you of course, but my advice is that you should set the new |
Okay, I agree. Does that mean I'm misinterpreting https://ws-rs.org/api_docs/src/ws/src/result.rs.html#44 when it states that the connection will disconnect? Or is that documentation wrong in light of the bug?
Does
That's what I saw too - even if I did a
Yeap, seems like an obvious win. I'd have to do some pre-processing in the percentage case (determine the total number of lines in the file to figure out the message count) but nothing horrid. As an aside (and this my naivety), where is the 5 * Thanks for your time! (and apologies again if I'm being dumb) |
You are not dumb. This was definitely a weakness in the documentation and the implementation. Thank you for catching that in Sadly, there is no yield in vanilla mio and no yield yet in Rust. Maybe someday, but for now, the only way to get the queue cleared is to return from the function. The size of the queue is set here or here. If you look at those lines in master, you will see the old Thank you for pointing this stuff out! |
I'm (apparently) sending too many items to the internal queue and getting back:
However I don't see any calls on Sender that would allow me to determine if I'm about to fill up the queue? By the time I get the error back ws-rs is already disconnecting from the client.
Is there some method I can call that'd advise to sleep for a bit and try again?
Real world use case: https://github.com/nickhs/websocket_replay/blob/master/src/main.rs#L80
The text was updated successfully, but these errors were encountered: