Visitar URL original
Stop trailers carrying over to the next message in the C parser by henryiii · Pull Request #14317 · aio-libs/aiohttp · GitHub
Skip to content

Stop trailers carrying over to the next message in the C parser - #14317

Open
henryiii wants to merge 2 commits into
aio-libs:masterfrom
henryiii:henryiii/fix/trailer1
Open

henryiii wants to merge 2 commits into
aio-libs:masterfrom
henryiii:henryiii/fix/trailer1

Conversation

@henryiii

@henryiii henryiii commented Nov 6, 2026 •

Copy link
Copy Markdown

What do these changes do?

The C parser (only, Python parser is fine) has no end-of-header callback for trailers, so the last trailer stayed pending and was added to the headers for the next message. A Content-Encoding trailer also applied to the next message. This adds the two missing lines to fix this.

greptile-apps found a bug that I then fixed (second commit). When parsing fails after the body started, feed_data() drops the payload without an error. A handler waiting on the body hung, and the queued 400 was never sent. This could already happen with a bad chunk size or a bad trailer. The first fix also made it possible with a final trailer over max_headers, which exposed the bug. The payload now gets the error, matching the Python parser.

Are there changes in behavior for the user?

Trailers are not public (yet), so I don't think so.

Is it a substantial burden for the maintainers to support this?

No, just fixes for existing stuff (but not public API).

Related issue number

I was working on #1652, which stated trailer parsing is now added, and invited a pull request for a public API. Adding a public API would enable pelicanfs to request trailers and get better error messages. I ran into two bugs in the non-public trailer handling adding this; this is the first of those two bugs (plus a new bug). Once both are in, I can submit a PR to add the public API.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modifications, please add yourself to
    CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep the list in alphabetical order, the file is sorted by name.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<category>.rst for example
      (14006.contrib.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

    • ensure category is one of the following:

      • bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • feature: A new behavior, public APIs. That sort of stuff.
      • deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • doc: Notable updates to the documentation structure or build
        process.
      • packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation.
      Explain high-level effects affecting the end-users, for example:

      Test runner no longer crashes when loading non-ASCII contents
      in doctest text files -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense in a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

I'dd add myself and add a CHANGES entry once I have a PR number. (Done)

I added my standard Assisted-by trailer for AI assistance, but if you'd rather have no attribution, I can remove it.

I have two entries for the changelog since there were two bugs, let me know if I should do that differently.

Linting error is pre-existing (username spellcheck).

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.97%. Comparing base (e87b8b7) to head (30f8d9c).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
aiohttp/_http_parser.pyx 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14317      +/-   ##
==========================================
- Coverage   99.12%   98.97%   -0.15%     
==========================================
  Files         135      135              
  Lines       53439    53471      +32     
  Branches     2723     2723              
==========================================
- Hits        52969    52923      -46     
- Misses        357      434      +77     
- Partials      113      114       +1     
Flag Coverage Δ
Autobahn ?
CI-GHA 99.05% <100.00%> (-0.01%) ⬇️
OS-Linux 98.69% <100.00%> (-0.01%) ⬇️
OS-Windows 97.48% <100.00%> (+<0.01%) ⬆️
OS-macOS 98.34% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.29% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.37% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.37% <100.00%> (-0.01%) ⬇️
Py-3.14 98.39% <100.00%> (+<0.01%) ⬆️
Py-3.15 98.39% <100.00%> (+<0.01%) ⬆️
Py-3.15t 98.24% <100.00%> (+<0.01%) ⬆️
Py-pypy-3.12 96.95% <100.00%> (-0.01%) ⬇️
VM-macos-latest 98.34% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 98.69% <100.00%> (-0.01%) ⬇️
VM-windows-latest 97.48% <100.00%> (+<0.01%) ⬆️
cython-coverage 83.84% <96.87%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

llhttp has no end-of-header callback for trailers, so the last trailer
stayed pending and was added to the headers of the next message on the
connection. A Content-Encoding trailer also applied to the next message.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii
henryiii force-pushed the henryiii/fix/trailer1 branch from 7381639 to dada412 Compare November 6, 2026 21:49
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Nov 6, 2026
@henryiii
henryiii marked this pull request as ready for review November 6, 2026 21:52
@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; the earlier trailer-read hang is fixed.

Reviews (2) · Last reviewed commit: "Send parse errors to the active payload ..." · Reviewed by Greptile

Comment thread aiohttp/_http_parser.pyx Resolved
@codspeed

codspeed Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 50 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 102 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing henryiii:henryiii/fix/trailer1 (30f8d9c) with master (e87b8b7)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

feed_data() dropped the payload without an error, so a handler waiting on
the body hung and the queued 400 was never sent. Finishing the last trailer
in on_message_complete also made a rejected final trailer reach this path.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>

This branch has not been deployed

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

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant