-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Websocket client uses an unbounded buffer #1967
Comments
I don't get the question. If you want to throttle or do rate limit you should do inside it and not leave it as a blank impl. |
The default max frame size for ws codec is 64kb. So there is no unbounded buffer case. |
Hi @fakeshadow, I'm concerned more with the sending side than the receiving side. I'm thinking that the |
But you control the sending? Sorry you lost me. You are using reference: |
You can use |
Hi again @fakeshadow, thanks for the pointer. It's probably obvious to you, but I am new to Actix and so am unfamiliar with these APIs and was starting with the example to learn. Thanks for pointing out the Indeed the buffer does seem very reasonably constrained for a time, but eventually the server stopped receiving data and the client process' memory usage started to rise without bound again. I also didn't see an error returned from As an aside, do you think it would be good to either add a comment to the example repo highlighting this, or maybe converting it to use |
To clarify what I'm doing a little bit more, here's steps to reproduce what I am seeing:
This firewall rule is a way to simulate flaky network connections between client and server, and obviously I would not expect the messages to arrive at the server with this rule in place, but I would expect the client to halt accepting new messages and stay relatively low on memory usage in this condition. What do you think? |
Yea the examples are sometimes rough and not best practice. Sorry about that and some of them surely can and need to be improved.
Actor runs on it's own and the stream logic is separate from the Reference:
PRs and issues are welcome to improve the examples. Like I said some of them indeed are rough and like some improvement. |
Was this fixed? |
Expected Behavior
I expect that writing bytes into the websocket client would block or await (for an async API) until there is room in a bounded buffer, so as to constrain the memory consumed by the client.
Current Behavior
It seems that the client accepts bytes without bound, such that it will consume infinite memory if the rate of bytes in exceeds the rate of bytes out.
Possible Solution
Replace the client's buffer with a bounded buffer.
Steps to Reproduce (for bugs)
I've forked the example repository and made a small edit to the code so that it sends bytes rapidly into the client. I also adjusted the server to give a longer heartbeat timeout so that the effect is more obvious. You can see those changes here:
bowlofeggs/examples@09bceb4
Context
I've noticed memory climbing in a process that uses the actix websocket client. I discovered that the data out can be constrained at times, and it is not easy to guess or predict a rate to safely send data into the client.
Your Environment
awc-2.0.3 on Linux 5.10.12.
rustc -V
): rustc 1.47.0See also: #1956
The text was updated successfully, but these errors were encountered: