Skip to content

HTTPCORE-799: Reset async entity producer state after interrupted writes - #698

Merged
ok2c merged 1 commit into
apache:masterfrom
mkurz:HTTPCORE-799
Sep 17, 2026
Merged

ok2c merged 1 commit into
apache:masterfrom
mkurz:HTTPCORE-799

Conversation

@mkurz

@mkurz mkurz commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

This fixes HTTPCORE-799.

This was found while testing an HTTP/2 authentication retry in which a server returned a 401 response and then reset the stream with RST_STREAM(NO_ERROR). The request producer was released mid-write and then reused for the retry.

Repeatable async entity producers could retain state from an interrupted write when releaseResources() was called. Although the source was reset for a replay, internal staging buffers could still contain the unwritten tail, and a digesting decorator could still contain the bytes accepted before the interruption.

The affected producers now reset their per-production state when resources are released:

  • FileEntityProducer and PathEntityProducer clear their file buffers.
  • AbstractCharAsyncEntityProducer clears its encoded-byte buffer, fixing StringAsyncEntityProducer and other repeatable character producers.
  • AbstractBinAsyncEntityProducer clears its byte buffer, fixing repeatable binary subclasses.
  • DigestingEntityProducer resets its MessageDigest before releasing its wrapped producer.

Regression tests cover file, path, string, repeatable binary, and digesting producers. Before the buffer fixes, replaying abcdef after only abc had been accepted produced defabcdef; after the fixes it produces exactly abcdef. Before the digest fix, the replay body was correct but its MD5 was calculated over abcabcdef instead of abcdef.

The same affected code is present on the 5.4.x branch, so this change is also a candidate for backporting.

Tests:

  • ./mvnw -pl httpcore5 -Dtest=TestStringAsyncEntityProducer,TestAbstractBinAsyncEntityProducer,TestFileAsyncEntityProducer,TestPathAsyncEntityProducer test — 13 tests passed
  • ./mvnw -pl httpcore5 -Dtest=TestDigestingEntityProducer test — 2 tests passed
  • ./mvnw -pl httpcore5 test — 1,415 tests passed
  • ./mvnw -pl httpcore5 verify -DskipTests — checkstyle, Animal Sniffer, and japicmp passed

Discard buffered but unwritten bytes and partial digest state when async
entity producers are released, so repeating an interrupted production
starts cleanly from the beginning.

Add regression tests for file, path, string, repeatable binary, and
digesting producers.
@ok2c

ok2c commented Sep 17, 2026

Copy link
Copy Markdown
Member

@mkurz That was quite sloppy on my part. Thank you for finding and reporting the defects.

@ok2c
ok2c merged commit e99e078 into apache:master Sep 17, 2026
12 checks passed
@ok2c

ok2c commented Sep 17, 2026

Copy link
Copy Markdown
Member

Cherry-picked to 5.4.x

@mkurz
mkurz deleted the HTTPCORE-799 branch September 17, 2026 13:51
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.

2 participants