consumeAll: fail content with static exception except when debug logs are enabled + move exception management from HttpInput to ContentProducer

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-04-19 16:49:30 +02:00
parent 78dc11b648
commit 973dfcf4f7
4 changed files with 19 additions and 8 deletions

View File

@ -30,6 +30,14 @@ import org.slf4j.LoggerFactory;
class AsyncContentProducer implements ContentProducer
{
private static final Logger LOG = LoggerFactory.getLogger(AsyncContentProducer.class);
private static final Throwable UNCONSUMED_CONTENT_EXCEPTION = new IOException("Unconsumed content")
{
@Override
public synchronized Throwable fillInStackTrace()
{
return this;
}
};
private final AutoLock _lock = new AutoLock();
private final HttpChannel _httpChannel;
@ -151,11 +159,15 @@ class AsyncContentProducer implements ContentProducer
}
@Override
public boolean consumeAll(Throwable x)
public boolean consumeAll()
{
assertLocked();
Throwable x = UNCONSUMED_CONTENT_EXCEPTION;
if (LOG.isDebugEnabled())
LOG.debug("consumeAll [e={}] {}", x, this);
{
x = new IOException("Unconsumed content");
LOG.debug("consumeAll {}", this, x);
}
failCurrentContent(x);
// A specific HttpChannel mechanism must be used as the following code
// does not guarantee that the channel will synchronously deliver all

View File

@ -80,9 +80,9 @@ class BlockingContentProducer implements ContentProducer
}
@Override
public boolean consumeAll(Throwable x)
public boolean consumeAll()
{
boolean eof = _asyncContentProducer.consumeAll(x);
boolean eof = _asyncContentProducer.consumeAll();
_semaphore.release();
return eof;
}

View File

@ -46,7 +46,7 @@ public interface ContentProducer
* Doesn't change state.
* @return true if EOF was reached.
*/
boolean consumeAll(Throwable x);
boolean consumeAll();
/**
* Check if the current data rate consumption is above the minimal rate.

View File

@ -150,10 +150,9 @@ public class HttpInput extends ServletInputStream implements Runnable
{
try (AutoLock lock = _contentProducer.lock())
{
IOException failure = new IOException("Unconsumed content");
if (LOG.isDebugEnabled())
LOG.debug("consumeAll {}", this, failure);
boolean atEof = _contentProducer.consumeAll(failure);
LOG.debug("consumeAll {}", this);
boolean atEof = _contentProducer.consumeAll();
if (atEof)
_consumedEof = true;