Skip to content

AccessEvent cannot return cookies when Jetty Request is recycled #11

@marinedayo

Description

@marinedayo

Logback Access 2.0.1 and Jetty 11. (Probably also occurs in the previous Logback Access 1.4 series.

The issue occurs because the Jetty web server recycles org.eclipse.jetty.server.Request Objects. When the server completes processing a given Request object, the server recycles the Request Object. After the Request Object is recycled, any various data related to the previous request will no longer be available. For example, if using an appender that processes asynchronously, the Request object may be recycled before logging.

AccessEvent has prepareForDeferredProcessing method to avoid this, but the cookie is not considered here.

public void prepareForDeferredProcessing() {
getRequestHeaderMap();
getRequestParameterMap();
getResponseHeaderMap();
getLocalPort();
getMethod();
getProtocol();
getRemoteAddr();
getRemoteHost();
getRemoteUser();
getRequestURI();
getRequestURL();
getServerName();
getTimeStamp();
getElapsedTime();
getStatusCode();
getContentLength();
getRequestContent();
getResponseContent();
copyAttributeMap();
}

@Override
public String getCookie(String key) {
if (httpRequest != null) {
Cookie[] cookieArray = httpRequest.getCookies();
if (cookieArray == null) {
return NA;
}
for (Cookie cookie : cookieArray) {
if (key.equals(cookie.getName())) {
return cookie.getValue();
}
}
}
return NA;
}

Metadata

Metadata

Assignees

Labels

DONEIssue was fixed

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions