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

Jetty 12.0.x 12191 alt debug listener #12254

Merged
merged 14 commits into from
Sep 30, 2024

Conversation

janbartel
Copy link
Contributor

@janbartel janbartel commented Sep 10, 2024

This is an alternate solution to debug logging using the DebugHandler class instead of the eeX DebugListener classes (as per PR #12231).

The problem with #12231 is that all DebugListeners will share the same log file, which will lead to contention and sequencing problems. The solution would be to ensure that each context uses its own log, however, at the point in time at which the debug log is configured, nothing reasonably identifying is known about the context to which it is being applied. This is because the eeX-debug modules are applied before a context xml file that would configure identifying info about that context, such as the context path or the location of the war being deployed.

This PR takes a different approach, and uses a single DebugHandler inserted into the handler list instead. This guarantees proper locking of debug log file entries. I've enhanced the output of it so it more closely resembles the output of the DebugListener. One notable omission in the logging is the identity of the context of the request being logged. This is because at the point in time that the DebugHandler executes we have not yet picked which context the request will be routed to.

Fixes: #12191

Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

I agree removing module for per debug listener is a good idea, but lets keep the mechanism and document it.

This handler setup is OK, but the handler itself is in need of updating.

Comment on lines 102 to 104
[[eeN-debug]]
== Module `{ee-all}-debug`
include::{jetty-home}/modules/ee10-debug.mod[tags=description]
Copy link
Contributor

Choose a reason for hiding this comment

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

There is N, all and 10 in this paragraph

@@ -76,17 +95,44 @@ public boolean handle(Request request, Response response, Callback callback) thr
finally
{
// TODO this should be done in a completion event
print(name, "RESPONSE " + response.getStatus() + (ex == null ? "" : ("/" + ex)) + " " + response.getHeaders().get(HttpHeader.CONTENT_TYPE));
log("<< r=%s async=false %d%n%s", rname, response.getStatus(), response.getHeaders());
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to fix the TODO. At the time this finally block is called, the response status and headers may not be set, or we may be in a race with them being set.

Also async= doesn't mean much anymore.

So we need to wrap the callback and look at the return of the handle call to log all the possible outcomes:

  • handle == false then log("XX r=%s")
  • handle == true, callback complete then log("<< r=%s async=false ...
  • handle == true, callback not complete then log("|| r=%s async=true ...

In the callback, it should also check if handling has exited and if so it would need to log("<< r=%s ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

gregw
gregw previously approved these changes Sep 24, 2024
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Looks good.. but could have a bit more javadoc

Comment on lines 65 to 75
private boolean handlingCompleted()
{
//test if the request is still being handled or not
return !_handling.compareAndSet(true, false);
}

private void callbackCompleted(Throwable throwable)
{
if (_handling.compareAndSet(true, false))
log("<< r=%s async=false %d %s%n%s", findRequestName(_request), _response.getStatus(), (throwable == null ? "" : throwable.toString()), _response.getHeaders());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

javadoc on these methods would be helpful

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've changed the implementation to a) be more correct b) clearer and c) added more javadoc.

@janbartel janbartel merged commit 97ff548 into jetty-12.0.x Sep 30, 2024
10 checks passed
@janbartel janbartel deleted the jetty-12.0.x-12191-alt-debug-listener branch September 30, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

DebugListener module in core refers to non-existent org.eclipse.jetty.server.DebugListener
2 participants