Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #6973 - Setup Request/Response objects for success with RequestLog #7183

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,10 @@ public void onCompleted()
LOG.debug("onCompleted for {} written={}", getRequest().getRequestURI(), getBytesWritten());

if (_requestLog != null)
{
_request.onRequestLog();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not just move the call to _request.onCompleted() to before this line and then avoid creating another event and callback to the request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe onCompleted() is too late, by that point the request / response has been recycled already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also don't want all of the unnecessary steps (like the restoring) to occur if there's no RequestLog declared / active.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joakime I believe that we can move the call to onCompleted to be just before the request log steps. I think it is at least worth a try. It makes sense to not log the request until it's handling is completed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the fixing of Request to Request.onComplete() didn't work for the logback test suite.

Moving the fixing of the Request (contentParamsExtracted and status) to Request.onCompleted() breaks logging for session information (they get auth[nz] details out from sessions), and multipart information (file sizes), etc.

Currently, with the PR like it sits here, the RequestLog.log() occurs during HttpChannel.onComplete(), and before Channel idle timeout reset, and Request.onCompleted().
Turns out this location is the perfect place for RequestLog.log() to make sense.

We need another event before Request.onComplete() to fixate the Request/Response.
Or move the exiting behaviors in Request.onComplete() to a new event like Request.recycle() so we can use Request.onComplete() for RequestLog behaviors.
The two events with a RequestLog.log() in between is still needed.

Stated in a different way.

  1. HttpChannel.onComplete()
  2. Fixate Request/Response.
  3. RequestLog.log().
  4. Cleanup Request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a potential solution.
At least one that logback tests seem happy with.

_requestLog.log(_request, _response);
}

long idleTO = _configuration.getIdleTimeout();
if (idleTO >= 0 && getIdleTimeout() != _oldIdleTimeout)
Expand Down
14 changes: 14 additions & 0 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,20 @@ public String changeSessionId()
return session.getId();
}

protected void onRequestLog()
{
// Don't allow pulling more parameters
_contentParamsExtracted = true;

// Reset the status code to what was committed
MetaData.Response committedResponse = getResponse().getCommittedMetaData();
if (committedResponse != null)
{
getResponse().setStatus(committedResponse.getStatus());
// TODO: Reset the response headers to what they were when committed
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave all the restoring of state to a different PR, as it is a different issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only restoring response status code, which needs to happen for BadMessage during HttpParser.
There's still a long list of other restoring needed.
See the test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part 2 PR is much more comprehensive, this is the minimum in my view.
Example: We have the entire prevention of Request.getInputStream() and Request.getReader() usage during RequestLog as well in part 2. (which wasn't even in the old PR yet)
This is literally what the first commit in the old PR was, before you asked for the rest (isMutable, restoring response headers, preventing post-commit changes, etc) that belongs in part 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we can achieve PR2 with a change to the _errorSentAndIncludes field that will prevent mutations rather than needing to restore them.
I'll have a play with that, if you can reduce this PR down to the absolute minimum to fix the reading parameters problem- ie: move the onCompleted() call to before the request log and then set the parameter extracted boolean within the onCompleted call

}

/**
* Called when the request is fully finished being handled.
* For every session in any context that the session has
Expand Down
Loading