We found a bug in the hyper HTTP library
2 days ago
- #hyper
- #Cloudflare
- #race condition
- Cloudflare's Images service, built in Rust on Workers, runs on their edge network and uses hyper for HTTP connections.
- In late 2025, the Images binding was rearchitected for a more direct connection, but intermittent failures occurred for larger images, returning truncated responses with 200 status codes.
- A race condition in hyper caused premature socket shutdowns when the outbound buffer filled, leading to truncated image data being sent.
- The bug was triggered by a slower reader in the new intermediary service, which replaced FL, causing occasional buffer backpressure.
- Debugging involved strace to trace syscalls, revealing that shutdown was called before all data was flushed from hyper's buffer.
- The fix involved ensuring hyper flushes its buffer completely before shutting down the socket, resolved with a four-line code change.
- The fix was contributed to hyper upstream and will be included in future releases, while Cloudflare runs an internal patched version.
- The Images binding now supports both remote and hosted images, offering a unified media processing API on Cloudflare's platform.