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
{{ message }}
Repository navigation
If a client cancels streams the connection is reset. #1010
The maintainers seem to be already aware of this problem. I am just opening an issue for tracking because #983 hasn't gotten any review traction and #856 was closed without a fix.
I understand this was put in place to protect against an attack vector, but no other http2 library behaves like this. Cancelling streams is a perfectly normal thing to do regularly in steady state. If you cancel streams regularly with h2, the library resets your connection. This essentially makes the library unusable in production for any streaming use case because any other requests on the channel fail when the connection resets.
My use case is streaming multiple range scans back from bigtable, doing a merge-join across them, and cancelling the streams when the join has produced enough rows to fill a page. I can't know how many rows I need from the database until I have joined them, so every request ends in a cancellation. Cancellation is not an edge case.
Since I cancel every bigtable stream, the behavior #983 fixes in h2 is causing spurious fault spikes when the connection resets because the other range scans that were in-flight on those reset connections fail. This is ultimately causing my service to breach its availability SLA.
This is a huge pain point in the rust ecosystem.
Code Sample
Expected Behavior
I can cancel streams and my connection doesn't reset.
Actual Behavior
My connection resets when i cancel too many streams and all my other requests on that connection fail and I get paged and my users have a bad experience.
Let me try to lay out some of the details of how it works first:
There is a concept of "local reset strikes", such that as a peer sends bad things and forces us to send a reset, eventually over a certain amount this will cause the connection to close. This is a defense mechanism (other implementations have something like this) since dealing with a bunch of errors has compute cost and is a vector of attack.
When a stream is canceled locally (such as dropping the handles), a CANCEL is sent (which does not count as a reset strike), and the stream is put in a list of recently reset streams.
While a stream is part of the "recently reset streams", any incoming frames are ignored (hpack and window size taken care of). This "for a little while", to account for the remote peer sending frames before it learned of the reset.
We bound the "recently reset streams" list, because every stream we keep around has a memory cost. Unlimited size could allow the list to grow unbounded. It also has a time limit, since eventually we want to recap that memory, and the remote should know by then that the stream is closed.
Eventually, once a stream is finally forgotten about, any new frame that is received will trigger a local STREAM_CLOSED reset. This will count against the "local reset strikes". Without that, a malicious remote can close a stream, and if frames are ignored forever, the remote can force us to consume endless compute. (This can happen with any other implementation that does not limit how much it ignores of forgotten streams.)
If there is something about the above points that happens to be wrong, that detail would be a bug we should fix.
But beyond that, I feel like this is working as intended.
That said, if you have a workflow that requires canceling a significant amount of streams, and are willing to pay the memory cost of "remembering" more of them at a time, there are max_concurrent_reset_streams and max_concurrent_reset_duration options to increase. Is that not sufficient?
While a stream is part of the "recently reset streams", any incoming frames are ignored (hpack and window size taken care of). This "for a little while", to account for the remote peer sending frames before it learned of the reset.
This is where it's going wrong for me, because I cancel a lot of streams.
That said, if you have a workflow that requires canceling a significant amount of streams, and are willing to pay the memory cost of "remembering" more of them at a time, there are max_concurrent_reset_streams and max_concurrent_reset_duration options to increase. Is that not sufficient?
IIRC, there is no way to set these parameters through Tonic. I originally started going down the path of opening a Tonic PR to add that, but then saw #983. I guess making these parameters tunable through Tonic is the path I should pursue for the long term.
Also curious if you think it makes sense to adjust the defaults at all? I haven't done any sort of testing to see how much memory my use case would need, but I'd be happy to provide that data to you in a bit.
I am interested any data that might help provide better defaults, yea. They're mostly "that seems reasonable" guesses. (Currently defaults are up to 50 streams kept for 1 second.)
Also, it would be helpful to know if the limit and strikes are hit nearly at once, or if it's a slow overflow and eventually the strikes kill the connection.
The Edge service is connecting to the Cache in a trusted manner. The downstream client may disconnect, and we do want to immediately cease work on the fanned-out requests to the cache. But cancelling the Edge -> Cache requests does not mean that Edge is misbehaving or that there is anything wrong. Closing the whole connection only causes more load (errors, retries), not less, because it fails every other request on it.
Edge Service Internal Cache
│ │
│──────── request (stream 1) ──────>│
│ │
client disconnects, edge cancels: │
│──────── RST_STREAM(CANCEL) ──────>│
│ │
│<─────── late response DATA ───────│ (already in flight)
│ │
h2 has forgotten stream 1: │
│──────── RST_STREAM(STREAM_CLOSED)>│ +1 strike, never decays
│ │
... repeat until 1024 strikes ... │
│ │
│──────── GOAWAY ──────────────────>│ all requests on this
│ │ connection fail
I exposed the client knobs in tonic (grpc/grpc-rust#2972, tonic 0.14.9), so it's now easier to work around this. But I do think there's some change we could make here to make this less of a problem with or without config tweaking.
I had Claude survey (I have not verified it by hand) what other HTTP/2 clients do when frames arrive for a stream they cancelled:
Library
Late frames on a stream the client cancelled
Can this close the connection?
h2
Ignored while in the reset window (50 streams, 1s), then RST_STREAM plus a strike
Yes, after 1024 strikes over the connection's lifetime
Go x/net/http2, grpc-go
Ignored, flow control returned
No
Netty, grpc-java
Ignored, or a stream-level RST_STREAM that nothing counts
No
nghttp2, Envoy, gRPC C core
Ignored for any id at or below the last one sent, flow control returned
No
python-hyper/h2
RST_STREAM that nothing counts (65,536 closed streams remembered)
Only an edge case (late HEADERS after eviction)
Every reset-flood limit it found decays over time: nghttp2 uses a token bucket (burst 1000, 33/s), Netty a fixed window (200 per 30s), Envoy a ratio, and Go a gauge. It found no other implementation with a counter that only goes up.
Make max_local_error_reset_streams decay, for example as a token bucket. It still caps resets per second for an attacker. But a healthy long-lived connection would not reach the limit just by running long.
Even if (1) is blocked, should we look into (2) and (3)?
No, the point of the protection is that a malicious peer does not just continuously send frames on an old stream.
Make max_local_error_reset_streams decay, for example as a token bucket.
Maybe. I've been considering cleaning up several of these concepts into a temperature/overhead mechanism, kind of like Tomcat has. But, I think this is a separate issue.
Ultimately, I think there's two cases that different people might be running into:
A giant burst past the max_concurrent_reset_streams limit. Configuring it higher should help there.
A slow but constant amount of old streams sending past the eviction, ticking of the max reset strikes on a long lived connection.
I have a PR up to adjust the defaults to be a bit smarter, based on configuration intent: #1013
Activity
seanmonstar commentedon Nov 23, 2026
Let me try to lay out some of the details of how it works first:
If there is something about the above points that happens to be wrong, that detail would be a bug we should fix.
But beyond that, I feel like this is working as intended.
That said, if you have a workflow that requires canceling a significant amount of streams, and are willing to pay the memory cost of "remembering" more of them at a time, there are
max_concurrent_reset_streamsandmax_concurrent_reset_durationoptions to increase. Is that not sufficient?nickvikeras commentedon Nov 23, 2026
This is where it's going wrong for me, because I cancel a lot of streams.
IIRC, there is no way to set these parameters through Tonic. I originally started going down the path of opening a Tonic PR to add that, but then saw #983. I guess making these parameters tunable through Tonic is the path I should pursue for the long term.
Thanks
nickvikeras commentedon Nov 23, 2026
Also curious if you think it makes sense to adjust the defaults at all? I haven't done any sort of testing to see how much memory my use case would need, but I'd be happy to provide that data to you in a bit.
seanmonstar commentedon Nov 23, 2026
I am interested any data that might help provide better defaults, yea. They're mostly "that seems reasonable" guesses. (Currently defaults are up to 50 streams kept for 1 second.)
Also, it would be helpful to know if the limit and strikes are hit nearly at once, or if it's a slow overflow and eventually the strikes kill the connection.
nickvikeras commentedon Nov 23, 2026
Oh looks like someone already added this to Tonic: grpc/grpc-rust#2972
I will try and move my service off my h2 fork and tune these params to see if I can solve the problem that way.
adriangb commentedon Nov 23, 2026
I agree the defense makes sense when the peer is untrusted. My case is a trusted peer:
The Edge service is connecting to the Cache in a trusted manner. The downstream client may disconnect, and we do want to immediately cease work on the fanned-out requests to the cache. But cancelling the Edge -> Cache requests does not mean that Edge is misbehaving or that there is anything wrong. Closing the whole connection only causes more load (errors, retries), not less, because it fails every other request on it.
I exposed the client knobs in tonic (grpc/grpc-rust#2972, tonic 0.14.9), so it's now easier to work around this. But I do think there's some change we could make here to make this less of a problem with or without config tweaking.
I had Claude survey (I have not verified it by hand) what other HTTP/2 clients do when frames arrive for a stream they cancelled:
RST_STREAMplus a strikeRST_STREAMthat nothing countsRST_STREAMthat nothing counts (65,536 closed streams remembered)Every reset-flood limit it found decays over time: nghttp2 uses a token bucket (burst 1000, 33/s), Netty a fixed window (200 per 30s), Envoy a ratio, and Go a gauge. It found no other implementation with a counter that only goes up.
Some suggestions that come out of this:
max_local_error_reset_streamsdecay, for example as a token bucket. It still caps resets per second for an attacker. But a healthy long-lived connection would not reach the limit just by running long.Even if (1) is blocked, should we look into (2) and (3)?
seanmonstar commentedon Nov 24, 2026
No, the point of the protection is that a malicious peer does not just continuously send frames on an old stream.
Maybe. I've been considering cleaning up several of these concepts into a temperature/overhead mechanism, kind of like Tomcat has. But, I think this is a separate issue.
Ultimately, I think there's two cases that different people might be running into:
max_concurrent_reset_streamslimit. Configuring it higher should help there.I have a PR up to adjust the defaults to be a bit smarter, based on configuration intent: #1013
nickvikeras commentedon Nov 25, 2026
I configured h2 to use these values on my bigtable client using @adriangb's recent contribution to tonic:
This solved the problem for me and the additional memory use is negligible, at least for my use case.