Skip to content

HTTP/3 proxy teardown leaks ngtcp2/nghttp3/OpenSSL connection state #23327

Closed

Description

@cmeister2

I did this

I made one successful tunneled HTTP/1.1 request through an HTTP/3 proxy with
the public libcurl API, then cleaned up the easy handle normally. The transfer
returns CURLE_OK, but LeakSanitizer reports that the proxy-side ngtcp2,
nghttp3, and OpenSSL QUIC connection state is still allocated:

* Establishing HTTP/3 proxy tunnel to origin.test:80
[proxy] CONNECT origin.test:80
* CONNECT tunnel established, response 200
> GET /repro HTTP/1.1
[proxy] TUNNEL GET /repro HTTP/1.1
< HTTP/1.1 200 OK
[client body] OK
[client] curl_easy_perform: 0 (No error)

==3969195==ERROR: LeakSanitizer: detected memory leaks
...
SUMMARY: AddressSanitizer: 54543 byte(s) leaked in 68 allocation(s).

The largest retained allocations are the ngtcp2 connection (conn_new, 9,988
bytes), an nghttp3 stream slab (5,264 bytes), and OpenSSL QUIC crypto buffers.
LSan's full graph also contains the HTTP/3 streams, QPACK state, packet and
retransmission queues, TLS state, and related buffers.

This appears to be a missing teardown step in the experimental HTTP/3 proxy
filter. cf_h3_proxy_ctx_free()
only calls Curl_cf_ngtcp2_ctx_cleanup() before freeing the proxy context.
Curl_cf_ngtcp2_ctx_cleanup()
cleans common buffers and TLS bookkeeping, but it does not delete
ctx->h3conn, ctx->qconn, or (with OpenSSL QUIC API 2) ctx->ossl_ctx.

The ordinary, non-proxy ngtcp2 filter has the missing close phase in
cf_ngtcp2_ctx_close():
it calls nghttp3_conn_del(), ngtcp2_conn_del(), and
ngtcp2_crypto_ossl_ctx_del() before the context is released. The proxy
destroy path does not call an equivalent function, so its opaque connection
objects become unreachable when cf_h3_proxy_ctx_free() frees the containing
curl context.

I have put a standalone public-libcurl reproducer here:

https://gist.github.com/cmeister2/ac95f81872d168f051453fa725740499

It contains:

  • client.c: a small libcurl client using CURLPROXY_HTTPS3
  • proxy.py: a local aioquic HTTP/3 CONNECT peer
  • requirements.txt: the pinned Python dependency
  • run.sh: build/orchestration script with ASan/LSan settings

With an ASan-enabled curl installation built with ngtcp2 and experimental
HTTP/3 proxy support:

python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
CURL_CONFIG=/path/to/curl-install/bin/curl-config \
  PYTHON=.venv/bin/python ./run.sh

The runner uses an ephemeral loopback UDP port, creates an ephemeral
self-signed proxy certificate, prints both sides of the successful transfer,
and enables LSAN_OPTIONS=report_objects=1. GDB=1 also stops at
cf_h3_proxy_ctx_free() and prints the three still-live opaque handles.

I reproduced this using unmodified curl and unmodified ngtcp2/nghttp3 source.
I am reporting it as a memory/resource cleanup bug, not a security issue.

I expected the following

Destroying the HTTP/3 proxy filter should release its nghttp3, ngtcp2, and
OpenSSL QUIC connection objects, as the direct HTTP/3 filter does. After the
successful request and normal curl_easy_cleanup(), LeakSanitizer should not
report the retained proxy connection graph.

The likely fix is to share or factor the full ngtcp2 close path so the proxy
filter performs the same handle deletion and ordering before common context
cleanup.

curl/libcurl version

curl/libcurl 8.23.0-DEV
curl commit f8423b9780dae1ce38bc2fcbcc6def5a9c3cea7d
ngtcp2 1.25.0
nghttp3 1.18.0
OpenSSL 4.0.3
aioquic 1.3.0 (reproducer peer)

Relevant build options include USE_NGTCP2=ON and the experimental
USE_PROXY_HTTP3=ON.

operating system

Linux x86_64 (Ubuntu 24.04 userspace, glibc 2.39), clang AddressSanitizer and
LeakSanitizer

Activity

  1. icing commented on Oct 9, 2026

    @icing
    Contributor

    Thanks! Could you verify that #23330 fixes this in your setup?

  2. added a commit that references this issue on Oct 9, 2026
  3. added a commit that references this issue on Oct 9, 2026
    e94fb70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions