jira-importer opened a new issue, #1356: URL: https://github.com/apache/httpcomponents-core/issues/1356
**[Eugene Kirpichov](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=jkff)** opened **[HTTPCORE-200](https://issues.apache.org/jira/browse/HTTPCORE-200?redirect=false)** and commented The method ContentLengthInputStream.close() reads the entity content to end. It does so in a non-interruptible fashion, and thus, if the entity content is too long (or even infinite), the method may take too much time or not terminate at all. I have actually observed this behavior: my program does a time-limited web crawl and, after the time limit is exceeded, interrupts the crawler thread and expects it to finish soon. The thread didn't finish in several minutes after the interrupt, because it was stuck in consumeContent() for some very large entity. Actually, execution time of this method for an entity of size N is limited by soTimeout * N / ContentLengthInputStream.BUFFER_SIZE for the worst case where each call to read() in the close() method almost causes a socket timeout. This upper limit is definitely too large, especially for a method that is supposed to release resources. It would of course be best if interrupting the thread just caused an IOException in the underlying SocketInputStream.read(), but I know that this functionality is not implemented in the JVM (and probably not going to be), so we need a workaround. I suggest that ContentLengthInputStream.close() (or someone down its call stack) check for Thread.currentThread.isInterrputed() between reads from the socket and throw an InterruptedIOException if it returns true. Probably, this might be done in AbstractSessionInputBuffer.fillBuffer(). If done so, execution time of this method will be limited by 2*soTimeout, which is already acceptable and at least predictable. --- **Affects:** 4.0 -- 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]
