Skip to content

Commit

Permalink
Cleanup request/response recycle #4711
Browse files Browse the repository at this point in the history
Reordered recycle in request and response to field order so that we can check that all fields are recycled.
  • Loading branch information
gregw committed Nov 11, 2020
1 parent 3660e38 commit a99ab04
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
91 changes: 44 additions & 47 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,74 +1857,71 @@ public boolean hasMetaData()

protected void recycle()
{
getHttpChannelState().recycle();
_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)
{
if (ServletAttributes.class.equals(_attributes.getClass()))
_attributes.clearAttributes();
else
_attributes = null;
}
setAuthentication(Authentication.NOT_CHECKED);
_contentType = null;
_characterEncoding = null;
if (_context != null)
throw new IllegalStateException("Request in context!");

if (_inputState == INPUT_READER)
_context = null;
_errorContext = null;
if (_cookies != null)
_cookies.reset();
_dispatcherType = null;
if (_reader != null)
{
try
{
int r = _reader.read();
while (r != -1)
{
r = _reader.read();
}
}
catch (Exception e)
{
LOG.ignore(e);
_reader = null;
_readerEncoding = null;
}
}

_dispatcherType = null;
setAuthentication(Authentication.NOT_CHECKED);
getHttpChannelState().recycle();
if (_async != null)
_async.reset();
_async = null;
_asyncNotSupportedSource = null;
_handled = false;
_attributes = Attributes.unwrap(_attributes);
if (_attributes != null)
{
if (ServletAttributes.class.equals(_attributes.getClass()))
_attributes.clearAttributes();
else
_attributes = null;
}
_contentType = null;
_characterEncoding = null;
_contextPath = null;
if (_cookies != null)
_cookies.reset();
_cookiesExtracted = false;
_context = null;
_errorContext = null;
_newContext = false;
_pathInfo = null;
_inputState = INPUT_NONE;
_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 a99ab04

Please sign in to comment.