Skip to content

http2: fail the parent transfer on CURL_PUSH_ERROROUT - #23481

Closed
Marti2203 wants to merge 2 commits into
curl:masterfrom
Marti2203:h2-push-errorout
Closed

Marti2203 wants to merge 2 commits into
curl:masterfrom
Marti2203:h2-push-errorout

Conversation

@Marti2203

Copy link
Copy Markdown
Contributor

When a CURLMOPT_PUSHFUNCTION callback returns CURL_PUSH_ERROROUT, the documentation says it "rejects the pushed stream and returns an error back on the parent stream making it get closed with an error". In practice the pushed stream is rejected, but the parent transfer finishes with CURLE_OK.

In on_stream_frame(), the callback's return value in rv is overwritten by the return value of nghttp2_submit_rst_stream(), which is 0 on success. So the rv == CURL_PUSH_ERROROUT check right after it can never match, and the CURLE_RECV_ERROR path is unreachable. This change keeps the nghttp2 return value in a separate variable.

I checked it with a small multi program whose push callback returns CURL_PUSH_ERROROUT, against nghttpd --no-tls -p /=/pushed.txt using CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE:

  • master: the parent transfer completes with CURLE_OK (0)
  • with this change: the parent fails with CURLE_RECV_ERROR (56)
  • CURL_PUSH_DENY still leaves the parent transfer at CURLE_OK

I did not add a test, as the existing push tests in tests/http/test_09_push.py need httpd with mod_http2, which I could not run locally. I'm happy to add a case there if that's wanted.

The issue was found with an LLM-assisted static analysis tool and verified manually.

When the push callback returned CURL_PUSH_ERROROUT, the return code was
overwritten by the result of nghttp2_submit_rst_stream(), so the check
for CURL_PUSH_ERROROUT could never match and the parent transfer
completed successfully instead of failing as documented in
CURLMOPT_PUSHFUNCTION.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The newly reachable error path can fail an unrelated multiplexed transfer instead of recording the error on the parent.

1 open issue
What changed in this PR

This PR fixes HTTP/2 push handling so CURL_PUSH_ERROROUT reaches the parent-transfer error path.

Changes:

  • Preserves the push callback result separately from the stream-reset result.
  • Keeps fatal reset-submission error handling intact.
File Description
lib/​http2.c Separates callback and nghttp2 return values during push rejection.

Review effort: Balanced

Comment thread lib/http2.c
h2rv = nghttp2_submit_rst_stream(ctx->h2, NGHTTP2_FLAG_NONE,
frame->push_promise.promised_stream_id,
NGHTTP2_CANCEL);
if(nghttp2_is_fatal(h2rv))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed it to store the error in the parent stream's xfer_result and mark it dirty, so the parent transfer fails with CURLE_RECV_ERROR and other streams are unaffected. With the push callback returning CURL_PUSH_ERROROUT the parent now fails with 56, and CURL_PUSH_DENY still completes normally.

Returning an error from the frame callback fails nghttp2 input
processing for the whole connection, so the error could be reported on
whichever transfer happened to drive the session. Store it in the
parent stream's xfer_result instead and mark the parent dirty, so it is
reported on the parent transfer only.
@bagder bagder closed this in a51ead9 Oct 19, 2026
@bagder

bagder commented Oct 19, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants