You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Keep-alive from inside the read loop. DAS's own heartbeats drive it, so the timer thread is gone. A write to a closed portal socket throws there, which unwinds the read and closes the DAS connection for free.
A dedicated WebClient for the streamed DAS endpoints. A RestTemplate cannot cancel mid-response, and the cancel is what closes the socket DAS is watching. The connector is a fork of Spring's JdkClientHttpConnector without the cache(0) on the response body, which swallows the cancel.
A dedicated thread pool for SSE work instead of ForkJoinPool.commonPool(), which runs one thread on a 2-vCPU container, so a single slow estimate blocked every other SSE request.
Good call, and I did try it — WebClient.bodyToFlux(ServerSentEvent<String>) is the one Spring client that decodes text/event-stream, and it deletes ~90 lines of hand-rolled frame parsing.
However it doesn't work here:
With the default JdkClientHttpConnector, cancelling the stream doesn't close the connection. Spring's JdkClientHttpResponse#adaptBody ends in .cache(0), which never passes the cancel up to the JDK, so the socket to DAS stays open and DAS keeps computing an estimate nobody will read. That's the exact bug this PR want to fix.
Measured by AI against a real socket — consume two frames, then cancel:
Transport
Upstream sees disconnect
What's on this branch today (RestTemplate, closing the InputStream)
yes
WebClient + JdkClientHttpConnector
never
WebClient + ReactorClientHttpConnector
yes, 762ms
WebClient + ReactorClientHttpConnector would work - the connector that does cancel properly needs reactor-netty-http: 11 new artifacts (reactor-netty-core、reactor-netty-http、netty-codec-dns、netty-resolver-dns、nett
y-resolver-dns-classes-macos、netty-resolver-dns-native-macos、netty-codec-socks... ) plus a second HTTP stack with its own event loop, to serve one endpoint.
It works, so I'm happy to go this way if you'd rather — it just felt like a lot to pay for deleting a parser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Main changes:
RestTemplatecannot cancel mid-response, and the cancel is what closes the socket DAS is watching. The connector is a fork of Spring'sJdkClientHttpConnectorwithout thecache(0)on the response body, which swallows the cancel.ForkJoinPool.commonPool(), which runs one thread on a 2-vCPU container, so a single slow estimate blocked every other SSE request.