Skip to content

bench.sh: runtime and implementation apart, h2v2 on COROSIO, closed-stream fix - #49

Merged
pgit merged 6 commits into
masterfrom
bench-runtime-impl
Nov 16, 2026
Merged

pgit merged 6 commits into
masterfrom
bench-runtime-impl

Conversation

@pgit

@pgit pgit commented Nov 16, 2026

Copy link
Copy Markdown
Owner

What

  • bench.sh names each row by server program, I/O runtime and protocol implementation in separate columns (anyhttp/nghttpd; asio/corosio/libev; beast, nghttp2, nghttp2v2, ngtcp2+nghttp3). It used to have a single "server" column, so the h2v2 row didn't say which runtime it ran on. -2 now runs the nghttp2 version 2 build on both runtimes. On a terminal the output is in colour: asio blue, corosio orange, nghttpd grey, and ratios green or red when they differ from asio by more than 5%. NO_COLOR turns colour off.
  • New presets: build-corosio-h2v2-release (for bench.sh -2) and build-corosio-h2v2-asan.
  • Fix, h2v2: the server crashed on COROSIO when a handler sent its response after the connection had ended.
  • Fix, h2: version 1 gets the same guards, plus some small alignment with h2v2.

The crash

Found with scripts/bench.sh -2 -P -i -t 40 -u /test/data/64kminus1: the COROSIO + nghttp2v2 server segfaulted in nghttp2_conn_submit_response with conn == nullptr when h2load cut off the 64 KiB responses at the end of the run.

When a connection ends, the send loop closes the streams that are left and do_session() deletes the nghttp2 connection. A handler that hasn't sent its response yet can still hold one of those streams. async_submit() checked only that the stream existed, not that it was closed. On ASIO the handler happened to resume while end_connection() was still running, so nghttp2 still existed and just refused the closed stream. On COROSIO the handler resumed after the connection was gone. ASAN reported a read of the zero page, not a use-after-free; build-h2v2-asan (ASIO) ran clean.

Now a closed stream makes async_submit() fail with connection_aborted, and read_callback() no longer extends the receive window of a closed stream. Version 1 has the same unguarded code and gets the same two guards. One behaviour change there: v1 ignored nghttp2's refusal and told the handler the submit had succeeded; now it reports connection_aborted, as h2v2 does.

Alignment of h2/ with h2v2/: goaway_sent_ moves to the same place in the member list, and two unused stream members (pending, unhandled) are removed. Everything else that differs comes from the two nghttp2 APIs themselves.

Testing

  • Reproducer: server with 40 independent threads, h2load cutting off 64 KiB responses. Before the fix it crashed in the first round, in Release (under gdb) and under ASAN. After it, 10 rounds under ASAN and 8 in Release ran clean, and the new guard fired 20-80 times per round.
  • Unit tests: test_all passes on build, build-corosio, build-h2v2, build-corosio-h2v2-release and build-corosio-h2v2-asan (gtest-parallel).
  • Not run: scripts/check_package.sh (no CMakeLists.txt or public header changed) and the TLS variant (ANYHTTP_TEST_SCHEME=https).

🤖 Generated with Claude Code

pgit and others added 6 commits November 16, 2026 21:18
When a connection ends, the send loop closes the streams that are left and
do_session() deletes the nghttp2 connection, setting conn to nullptr. A handler
that is yet to submit its response can still hold such a stream, and
async_submit() checked only that the stream existed, so it handed nghttp2 a
null conn. On ASIO the handler happened to resume while end_connection() still
ran and nghttp2 merely refused the closed stream; on COROSIO it resumes after,
and the server crashed in nghttp2_conn_submit_response.

A closed stream now completes the submit with connection_aborted, as nghttp2's
refusal did, and read_callback() no longer extends the window of a closed
stream, whose rest of the body may be read after the connection is gone.

Found with scripts/bench.sh -2 -P -i -t 40 -u /test/data/64kminus1, h2load
cutting off the responses at the end of the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
build-corosio-h2v2-release/, so that bench.sh -2 has nghttp2 version 2 on
both I/O runtimes, and build-corosio-h2v2-asan/, where the h2v2 crash on a
closed stream showed under ASAN while build-h2v2-asan/ ran clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each row names the server program, its I/O runtime and the protocol
implementation in columns of their own (anyhttp/nghttpd; asio, corosio,
libev; beast, nghttp2, nghttp2v2, ngtcp2+nghttp3), instead of one "server"
name that folded runtime and implementation together, which left the h2v2 row
unclear about its runtime. -2 now runs the nghttp2 version 2 build of both
runtimes.

On a terminal the runtimes are in colour (asio blue, corosio orange, nghttpd
grey), and so are the implementations and the ratios that differ from asio by
more than 5%. NO_COLOR turns that off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The same guards as h2v2's: when the connection ends, nghttp2 closes the
streams that are left and do_session() deletes the session, while a handler
that is yet to submit can still hold one of them. async_submit() then handed
nghttp2_submit_response2() a stream nghttp2 no longer knew -- or a null
session -- and, ignoring the refusal, told the handler it had succeeded. A
closed stream now completes the submit with connection_aborted, as on h2v2,
and read_callback() no longer consumes on a closed stream.

Also aligns h2/ with h2v2/ where they had drifted apart: goaway_sent_ moves
to where h2v2 has it, and the stream's unused pending and unhandled go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge of master took this branch's table, which has a format of its own
for the data rows, and so lost the 11 columns of 693f381.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pgit
pgit merged commit 3b4b0c5 into master Nov 16, 2026
12 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.

1 participant