-
Notifications
You must be signed in to change notification settings - Fork 33
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
Out of memory - any way to optimize? #21
Comments
@rexxars Our main use case for this library does something very similar-- we use heartbeats sent every 3 minutes. We have not encountered this problem-- but we'd be happy to help investigate. Can you share the version of the library you're using, as well as a heap dump if you can produce one? |
I can't seem to reproduce the problem on the Android emulator, which is annoying. It seems to be garbage collecting memory just fine. I'm using:
I'll try updating to okhttp-eventsource 1.5.0, though it shouldn't make any difference judging by the commits. |
@rexxars keep us posted if you discover more. We have still not encountered this issue in our own usage. |
Out of interest, are you using this over HTTP or HTTPS? HTTP2? I'm encountering this issue over HTTPS with HTTP2, not sure if that makes any difference. When it crashes, I'm seeing two different OutOfMemoryErrors. One being the one I mentioned in the original post, and the other is:
After the crashing, I'm seeing one of these:
It might be interesting to note that this doesn't happen for quite a while, we're talking hours of just receiving ping-replies and reconnecting every 30 minutes (server closes connection, client reconnects). I'm also curious if this could be related to the way the load balancer forcefully terminates the connection. The transfer encoding used is chunked, and it expects the stream to end with a zero-byte chunk. However, the load balancer is not aware of this fact and just forcefully closes after 30 minutes. I'm pondering if somehow this could cause connections to remain open or leak memory. I'm going to try reproducing the issue with a real device against a local HTTP endpoint, and might also take the time to see if I can create a server replicating the load balancer cut-off behaviour. |
Sorry, this was all on my end. When the eventsource closed, I had written some faulty code that triggered a new EventSource to be instantiated for every disconnect. With a 30 minute timeout, this took quite a while to build up to a out of memory error, but locally with a 15 second timeout the error was much easier to spot. Sorry about this, thanks for a great library! |
Hi there!
I'm creating a fairly simple Android-app that simply displays some text based on EventSource messages. It runs on some fairly old and memory limited devices; the one in question has a total of 288MB of memory available.
The app runs for a while, but after a while it runs out of memory. There is rarely any messages published on the EventSource, but every 15 seconds we send a
ping
to keep the socket alive, which is basically only a:\n\n
sequence. So our stream looks something like this:I'm curious as to whether there is any way to optimize the code for a lower memory footprint, or if this is a bug somehow.
A potential workaround might be closing and reopening the connection every once in a while, but I'm not sure it solves the issue, and it also feels like a hack.
Any ideas?
Full stack trace follows:
The text was updated successfully, but these errors were encountered: