-
Notifications
You must be signed in to change notification settings - Fork 257
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
memory leak of ReceivePort when using create_stream #1836
Comments
Good observation! What about we close the port using a Looking forward to your PR (especially given that you have already had thorough understanding about the problem)! Alternative, I will fix it in the next batch, probably within a week (but this is a good-first-issue). |
i commented on that as well. it's not valid because then the receive port will be closed while the rust side "sendPort" is still open and rust might send events. I'd suggest that the generated code will know how to close the stream and when a client cancells subscription, the streams should be closed as well |
there is another issue with the way listen is implemented. the use of "async*" is not optimal because the actual call to rust's create_stream is asynchronous and that might cause issues. here is another example:
let's assume that "sendEvent" calls rust which then sends an event. a better implementation would be to call rust synchronously, during the listen method and that would make the stream ready on both sides |
Get it. I will take a look at it a bit deeper hopefully within 24 hours and reply here. |
Disclaimer: Too tired today, all words below may be very silly :/
Then if rust side sends events, it just provide errors to the rust function (if it silently swallow it then it is definitely bad!). Maybe this is good behavior?
Good observation! I guess one simple way may be to move the parts that we want to execute synchronously outside of the |
Related: #1867 |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue. |
Describe the bug
the current implementation closes the receive port when a "done" is received on the stream, but if the dart side cancelled the subscription before receiving "done", then the receive port will remain open on the dart side. Then, even if closing the stream, the receive port will never be released.
an alternative would be the close outside the for loop, but that would cause another issue.
if a client (dart side) closes the port, there could be a race where rust can still send through the sendPort and that would lead to an error.
see the code below.
Steps to reproduce
// the below code demonstrates how the leak can happen. all is needed to cancel the subscription and the receive port will remain open
Logs
Expected behavior
No response
Generated binding code
No response
OS
No response
Version of
flutter_rust_bridge_codegen
No response
Flutter info
No response
Version of
clang++
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: