HTTP/2 pooled singleflight: 8 loopback TLS accepts under concurrent first requests (final-lock TOCTOU)

Open
#32,717 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
18/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Domain
networking

Research direction

Start with Transport.h2_dial_and_do in vlib/net/http/transport_h2.v, where the pool check and the final dial decision happen under separate mutex acquisitions. Then run the failing test test_h2_pool_dial_dedup_race at vlib/net/http/transport_h2_test.v:527 repeatedly to confirm the interleaving. Done means that test passes reliably with exactly one accepted connection and eight HTTP 200 responses, without weakening the assertions.

Written by the indexing model from the issue text.

Description

Actual executed master failure (not workflow-container state)

  • Master SHA d8083d40873efc7689abdb15f4ca21b4f5d59f4a, Clang Linux production shard 3 job 136897140339, finished 2026-11-21 23:26 UTC, after 210 executed passes / 19 skips.
  • The single actual failing test is vlib/net/http/transport_h2_test.v:527 test_h2_pool_dial_dedup_race. Eight concurrent fetch(enable_http2:true) callers all returned HTTP 200 but the scripted h2 TLS server counted 8 accepted connections, versus the expected 1 shared, multiplexed connection. Original reproduction: ./vprod -cc clang -silent vlib/net/http/transport_h2_test.v, ideally repeated/with -keepc. This was not an external upstream response (local loopback listener), a deliberate failing fixture, GitHub job timeout or missing package.
  • The test file has blob SHA 5515c23c6a680444b1e9ed722e3da8c62fdf110f on both the failing SHA and master 9621aa02fd7d7788700846e93242d08bd70a8aea: master advancement alone has not fixed/tested this.

Specific source-level race to discriminate

In vlib/net/http/transport_h2.v Transport.h2_dial_and_do:

  1. It first locks t.mu, checks t.dialing[key], then reads t.h2_conns[key] and t.key_proto[key], unlocks to try the pooled connection.
  2. Later it relocks and checks only t.dialing[key] before inserting a new H2DialCall and initiating a new ALPN/TLS dial. There is no recheck of h2_conns[key] at this final atomic decision point.

Therefore an interleaving exists where caller A passes the unlocked pool check, caller B finishes a dial (registers h2_conns[key] and deletes dialing[key]), and caller A's final lock sees no pending dial and starts a redundant connection. This is a concrete TOCTOU in the source; whether it accounts for all eight accepts in this observed execution is unproven until traced. The earlier #27643 review addressed a related recheck, but the last decision remains split across two mutex acquisitions. The scripted server intentionally advertises max concurrent streams 100, so its stream limit should not drive redial.

Focused fix/validation requirements

Instrument pool key, Transport identity, dial call/connection ids and transitions with thread identifiers for eight workers; check whether the default transport is shared, whether an h2 pooled conn is retired between requests, and whether the final-lock gap is exercised. Implement an atomic decision for a currently reusable pooled connection versus an in-flight call versus a new dial, without holding t.mu across TLS I/O or entering an unbounded retry; preserve GOAWAY/closed retry behavior and h1-only fallback. Run original test repeatedly on native Linux Clang (prod/default, VJOBS1/4) and other supported backends, plus existing test_h2_dial_and_do_reuses_pooled_conn_instead_of_redialing, GOAWAY, fallback and connection-close tests. Keep exact one-accept/eight-200 assertions; no skip, timeout inflation or weakening.

Status: unresolved / investigating / still applicable. No local V checkout/compiler/formatter or original corrected native run was available for a safe patch in this environment.

Dominant language
V
Stars
38.1k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
682

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vlang/v

All issues in vlang/v

Similar issues

More Networking issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.