Skip to content

fix: error instead of busy-looping when write returns Ok(0)#921

Merged
seanmonstar merged 1 commit into
hyperium:masterfrom
ArniDagur:fix-framed-write-write-zero
Jul 16, 2026
Merged

fix: error instead of busy-looping when write returns Ok(0)#921
seanmonstar merged 1 commit into
hyperium:masterfrom
ArniDagur:fix-framed-write-write-zero

Conversation

@ArniDagur

Copy link
Copy Markdown
Contributor

This fixes a bug we saw in production. There's a nasty interaction between h2 and the ktls crate. Namely:

  1. When the write-side of the connection is closed, the ktls crate returns Ok(0) instead of an error.
  2. h2 retries Ok(0) writes, instead of treating them as errors.

This led to busy looping, and 100% CPU utilization. Ideally, this should be fixed in both the h2 and ktls crates, but I'm targeting h2 first because of its central place in the ecosystem.

This fix mirrors existing logic in hyper HTTP/1: https://github.com/hyperium/hyper/blob/v1.10.1/src/proto/h1/io.rs#L285-L297

This fixes a bug we saw in production. There's a nasty interaction between `h2` and the `ktls` crate. Namely:

1. When the write-side of the connection is closed, the `ktls` crate returns `Ok(0)` instead of an error.
2. `h2` retries `Ok(0)` writes, instead of treating them as errors.

This led to busy looping, and 100% CPU utilization. Ideally, this should be fixed in both the `h2` and `ktls` crates, but I'm targeting `h2` first because of its central place in the ecosystem.

This fix mirrors existing logic in hyper HTTP/1: https://github.com/hyperium/hyper/blob/v1.10.1/src/proto/h1/io.rs#L285-L297

@seanmonstar seanmonstar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. Makes sense to me, thanks for the fix!

@seanmonstar
seanmonstar merged commit 7c97e89 into hyperium:master Jul 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants