diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContentProducer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContentProducer.java index 94022caaa020..d68d151ad763 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContentProducer.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContentProducer.java @@ -31,7 +31,7 @@ class AsyncContentProducer implements ContentProducer { private static final Logger LOG = LoggerFactory.getLogger(AsyncContentProducer.class); - private static final HttpInput.ErrorContent RECYCLED_ERROR_CONTENT = new HttpInput.ErrorContent(new IllegalStateException("ContentProducer has been recycled")); + private static final HttpInput.ErrorContent SENTINEL_ERROR_CONTENT = new HttpInput.ErrorContent(null); private final AutoLock _lock = new AutoLock(); private final HttpChannel _httpChannel; @@ -63,12 +63,12 @@ public void recycle() // Make sure that the content has been fully consumed before destroying the interceptor and also make sure // that asking this instance for content between recycle and reopen will only produce error'ed content. if (_rawContent == null) - _rawContent = RECYCLED_ERROR_CONTENT; + _rawContent = SENTINEL_ERROR_CONTENT; else if (!_rawContent.isSpecial()) throw new IllegalStateException("ContentProducer with unconsumed content cannot be recycled"); if (_transformedContent == null) - _transformedContent = RECYCLED_ERROR_CONTENT; + _transformedContent = SENTINEL_ERROR_CONTENT; else if (!_transformedContent.isSpecial()) throw new IllegalStateException("ContentProducer with unconsumed content cannot be recycled"); @@ -226,9 +226,13 @@ private void failCurrentContent(Throwable x) _rawContent = null; } - HttpInput.ErrorContent errorContent = new HttpInput.ErrorContent(x); - _transformedContent = errorContent; - _rawContent = errorContent; + HttpInput.Content finalContent; + if (x != null) + finalContent = new HttpInput.ErrorContent(x); + else + finalContent = SENTINEL_ERROR_CONTENT; + _transformedContent = finalContent; + _rawContent = finalContent; } @Override diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java index fdcfa8781826..7f6459624e9a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java @@ -297,10 +297,11 @@ private int read(ByteBuffer buffer, byte[] b, int off, int len) throws IOExcepti return read; } + boolean isError = content instanceof ErrorContent; Throwable error = content.getError(); if (LOG.isDebugEnabled()) - LOG.debug("read error={} {}", error, this); - if (error != null) + LOG.debug("read isError={} error={} {}", isError, error, this); + if (isError) { if (error instanceof IOException) throw (IOException)error;