Skip to content

Commit

Permalink
Cleanup request/response recycle #4711 (#5643)
Browse files Browse the repository at this point in the history
* Cleanup request/response recycle #4711

Reordered recycle in request and response to field order so that we can check that all fields are recycled.

* Fixed ordering of reader consumption

* update from review
  • Loading branch information
gregw committed Nov 16, 2020
1 parent f4c32e7 commit 850a033
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
62 changes: 31 additions & 31 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Expand Up @@ -194,8 +194,8 @@ public static Request getBaseRequest(ServletRequest request)
private String _contextPath;
private String _servletPath;
private String _pathInfo;
private boolean _secure;
private Object _asyncNotSupportedSource = null;
private boolean _secure;
private boolean _newContext;
private boolean _cookiesExtracted = false;
private boolean _handled = false;
Expand All @@ -210,12 +210,12 @@ public static Request getBaseRequest(ServletRequest request)
private CookieCutter _cookies;
private DispatcherType _dispatcherType;
private int _inputState = INPUT_NONE;
private BufferedReader _reader;
private String _readerEncoding;
private MultiMap<String> _queryParameters;
private MultiMap<String> _contentParameters;
private MultiMap<String> _parameters;
private String _queryEncoding;
private BufferedReader _reader;
private String _readerEncoding;
private InetSocketAddress _remote;
private String _requestedSessionId;
private UserIdentity.Scope _scope;
Expand Down Expand Up @@ -1857,13 +1857,9 @@ public boolean hasMetaData()

protected void recycle()
{
_metaData = null;
_originalURI = null;

if (_context != null)
throw new IllegalStateException("Request in context!");

if (_inputState == INPUT_READER)
if (_reader != null && _inputState == INPUT_READER)
{
try
{
Expand All @@ -1877,17 +1873,25 @@ protected void recycle()
{
LOG.ignore(e);
_reader = null;
_readerEncoding = null;
}
}

_dispatcherType = null;
setAuthentication(Authentication.NOT_CHECKED);
getHttpChannelState().recycle();
if (_async != null)
_async.reset();
_async = null;
_requestAttributeListeners.clear();
_input.recycle();
_metaData = null;
_originalURI = null;
_contextPath = null;
_servletPath = null;
_pathInfo = null;
_asyncNotSupportedSource = null;
_secure = false;
_newContext = false;
_cookiesExtracted = false;
_handled = false;
_contentParamsExtracted = false;
_requestedSessionIdFromCookie = false;
_attributes = Attributes.unwrap(_attributes);
if (_attributes != null)
{
Expand All @@ -1896,35 +1900,31 @@ protected void recycle()
else
_attributes = null;
}
setAuthentication(Authentication.NOT_CHECKED);
_contentType = null;
_characterEncoding = null;
_contextPath = null;
if (_cookies != null)
_cookies.reset();
_cookiesExtracted = false;
_context = null;
_errorContext = null;
_newContext = false;
_pathInfo = null;
if (_cookies != null)
_cookies.reset();
_dispatcherType = null;
_inputState = INPUT_NONE;
// _reader can be reused
_queryParameters = null;
_contentParameters = null;
_parameters = null;
_queryEncoding = null;
_remote = null;
_requestedSessionId = null;
_requestedSessionIdFromCookie = false;
_secure = false;
_scope = null;
_session = null;
_sessionHandler = null;
_scope = null;
_servletPath = null;
_timeStamp = 0;
_queryParameters = null;
_contentParameters = null;
_parameters = null;
_contentParamsExtracted = false;
_inputState = INPUT_NONE;
_multiParts = null;
_remote = null;
if (_async != null)
_async.reset();
_async = null;
_sessions = null;
_input.recycle();
_requestAttributeListeners.clear();
}

/*
Expand Down
Expand Up @@ -123,17 +123,20 @@ public HttpChannel getHttpChannel()

protected void recycle()
{
// _channel need not be recycled
_fields.clear();
_errorSentAndIncludes.set(0);
_out.recycle();
_status = HttpStatus.OK_200;
_reason = null;
_locale = null;
_mimeType = null;
_characterEncoding = null;
_encodingFrom = EncodingFrom.NOT_SET;
_contentType = null;
_outputType = OutputType.NONE;
// _writer does not need to be recycled
_contentLength = -1;
_out.recycle();
_fields.clear();
_encodingFrom = EncodingFrom.NOT_SET;
_trailers = null;
}

Expand Down

0 comments on commit 850a033

Please sign in to comment.