Matthias created HTTPCORE-799:
---------------------------------
Summary: FileEntityProducer and PathEntityProducer retain stale
buffered data after an interrupted write
Key: HTTPCORE-799
URL: https://issues.apache.org/jira/browse/HTTPCORE-799
Project: HttpComponents HttpCore
Issue Type: Bug
Components: HttpCore
Affects Versions: 5.5-beta2
Reporter: Matthias
h2. Description
{{FileEntityProducer}} and {{PathEntityProducer}} are repeatable, but they do
not fully reset their internal state when {{releaseResources()}} is called
before the current production has completed.
Both implementations close and clear the reference to the underlying file
channel and reset {{eof}}, but leave any unwritten bytes in their internal
{{ByteBuffer}}. On the next production, the file is reopened at position zero
while those stale bytes remain buffered. The stale suffix is therefore emitted
before the complete file.
For example, with file content {{abcdef}}:
# The producer reads {{abcdef}} and the data channel accepts only {{abc}}.
# {{releaseResources()}} is called, simulating an interrupted request.
# The same repeatable producer is used again.
# The second production emits {{defabcdef}} instead of {{abcdef}}.
This was exposed while testing an HTTP/2 authentication retry after the server
completed a {{401}} response and reset the request stream with
{{RST_STREAM(NO_ERROR)}}. That graceful reset releases the request producer
before the higher layer retries it. See
[HTTPCLIENT-2433|https://issues.apache.org/jira/browse/HTTPCLIENT-2433] for the
related HttpClient issue.
h2. Expected behavior
Calling {{releaseResources()}} should discard pending bytes and restore a
repeatable producer to the beginning of its source. A subsequent production
should emit exactly the original file.
h2. Actual behavior
Any bytes that were buffered but not accepted by the previous data channel are
prepended to the next production.
h2. Affected code
* {{org.apache.hc.core5.http.nio.entity.FileEntityProducer}}
* {{org.apache.hc.core5.http.nio.entity.PathEntityProducer}}
The problem is present in HttpCore 5.5-beta2 and current {{master}}.
h2. Proposed fix
Clear the internal {{ByteBuffer}} in each producer's {{releaseResources()}}
method. Add regression tests that interrupt production after a partial channel
write, release the producer, and verify that its next production contains the
original file exactly once.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]