-
Notifications
You must be signed in to change notification settings - Fork 35
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
Fix connection leaks after closing non-exhaustive EventSource. #91
base: main
Are you sure you want to change the base?
Fix connection leaks after closing non-exhaustive EventSource. #91
Conversation
Hello and thank you for bringing this to our attention and opening this PR. We will review when able to do so. Thank you! |
I am experiencing the same issue. Could you please review at your earliest convenience? |
@dlqkfzlr Maybe you can try okhttp-sse as an alternate choice. |
@LinZong I'm hesitant to use it because it's still in experimental support. Is okhttp-sse library more stable? |
@dlqkfzlr I had tried to use okhttp-sse on both client-side and server-side for about 1 year,so far so good. In fact, some famous LLM-related library like langchain4j also uses okhttp-sse to provide streaming response. |
Affected version
4.1.1
Problem
Okhttp connection won't closed properly after closing EventSource when SSE stream is not fully consumed.
Reproduce code
Reason
com.launchdarkly.eventsource.EventSource#close
will close underlyingokhttp3.Call
and package-privatecom.launchdarkly.eventsource.HttpConnectStrategy.Client#httpClient
if there is no specified httpClient from outside.Canceling a
okhttp3.Call
will:Condition for logging connection leak warning: connection.calls is not empty, but referring 'RealCall' was gone by GC, indicating RealCall was not detached with RealConnection properly.
The only way to initiative detach RealCall with RealConnection properly is calling
releaseConnectionNoEvents
method, which entrance is inmessageDone
method.Called from stream exhausted:
Called from closing Response.
But such method cannot be called either closing
Call
or closing connection pool. ClosingCall
is obvious, let's focus on closing conneciton pool.Possible Fixup
Close underlying
Response
in closeCurrentStream along with closingCall
at reading thread.