jira-importer opened a new issue, #1502: URL: https://github.com/apache/httpcomponents-core/issues/1502
**[Matthias](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER314701)** opened **[HTTPCORE-799](https://issues.apache.org/jira/browse/HTTPCORE-799?redirect=false)** and commented ## Description Several repeatable async entity producers do not fully reset their per-production state when `releaseResources()` is called before the current production has completed. ### Buffered output `FileEntityProducer`, `PathEntityProducer`, `AbstractCharAsyncEntityProducer`, and `AbstractBinAsyncEntityProducer` can retain bytes that the data channel did not accept. Although the underlying source is reset for a replay, the internal staging buffer still contains the unwritten tail, so those stale bytes are emitted before the complete entity. `StringAsyncEntityProducer` is affected through `AbstractCharAsyncEntityProducer`. Repeatable custom binary producers can be affected through `AbstractBinAsyncEntityProducer`. For example, with content `abcdef`: 1. The producer reads `abcdef` and the data channel accepts only `abc`. 2. `releaseResources()` is called, simulating an interrupted request. 3. The same repeatable producer is used again. 4. The second production emits `defabcdef` instead of `abcdef`. ### Digest state `DigestingEntityProducer.releaseResources()` delegates to the wrapped producer but does not reset its `MessageDigest`. If the first production writes `abc` before interruption and the replay writes `abcdef`, the replay body can be correct while `getDigest()` and the `digest` trailer contain the MD5 of `abcabcdef` (`89091e2d8ada6ecb23f3d2b71fb1764b`) instead of the MD5 of `abcdef` (`e80b5017098950fc58aad83c8c14978e`). ## Context This was exposed while testing an HTTP/2 authentication retry after a server returned a `401` response and then reset the stream with `RST_STREAM(NO_ERROR)`. The request producer was released mid-write and reused for the retry. See [HTTPCLIENT-2433](https://issues.apache.org/jira/browse/HTTPCLIENT-2433) for the related HttpClient issue. The HttpCore problem is not specific to HTTP/2 or authentication; it can occur whenever a repeatable producer is released after a partial write and then reused. ## Expected behavior Calling `releaseResources()` should discard pending output and reset all per-production digest state. A subsequent production should emit exactly the original entity, and its digest should cover only that production. ## Actual behavior Buffered but unwritten bytes can be prepended to the next production, and bytes accepted during an interrupted production can be included in the replay's digest. ## Affected code * `org.apache.hc.core5.http.nio.entity.FileEntityProducer` * `org.apache.hc.core5.http.nio.entity.PathEntityProducer` * `org.apache.hc.core5.http.nio.entity.AbstractCharAsyncEntityProducer` (including `StringAsyncEntityProducer`) * `org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityProducer` (for repeatable subclasses) * `org.apache.hc.core5.http.nio.entity.DigestingEntityProducer` The problem is present in HttpCore 5.4.3, 5.5-beta2, and the current `5.4.x` and `master` branches. ## Proposed fix Clear the internal staging buffers when the file, path, character, and binary producers are released. Reset `DigestingEntityProducer`'s `MessageDigest` before releasing its wrapped producer, while preserving the completed `digest` value returned by `getDigest()`. Add regression tests that interrupt production after a partial channel write, release the producer, and verify that the next production contains the original entity exactly once and calculates its digest only from the replayed bytes. Implementation: [apache/httpcomponents-core#698](https://github.com/apache/httpcomponents-core/pull/698) --- **Affects:** 5.4.3, 5.5-beta2 **Backported to:** [5.4.4](https://github.com/apache/httpcomponents-core/milestone/107?closed=1) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
