Skip to content

Replace LoggerThread with single-threaded executor #545

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

Closed
wants to merge 2 commits into from

Conversation

ppkarwasz
Copy link
Contributor

This provides an alternative solution to the LoggerThread problems described in #544.

It replaces LoggerThread with a single-threaded ExecutorService almost identical to the one used by FileHandler. This improves AsyncFileHandler in two aspects:

  • the thread created by the executor service always uses Tomcat JULI's classloader as TCCL, preventing a memory leak,
  • if an Error kills the working thread, it is regenerated by the executor service.

A test is provided to ensure that the previous overflow policies work as documented.

This solves the problem of failing logger thread by replacing it with a
single threaded `ExecutorService`.
@ppkarwasz ppkarwasz force-pushed the new-async-file-handler branch from 3cb92f1 to 8b03745 Compare August 20, 2022 14:09
@markt-asf
Copy link
Contributor

I think this is a better approach than the current code that uses a Thread. Therefore, I think we can close #544.

I have been reviewing the PR and overall I like it. I have noticed that it is possible to lose log messages during shutdown (add a 100ms delay just before the call to publish internal to simulate a large backlog). The threading approach originally suffered from this problem as well and I think the same solution will work (register uses of the AsyncHandler and explicitly shutdown the executor during JULI shutdown). I plan on working on this today.

markt-asf added a commit that referenced this pull request Aug 25, 2022
Replace logging thread for JULI's AsyncFileHandlerwith an executor to
protect against failure of the logging thread.
Based on pull request #545 by Piotr P. Karwasz.
markt-asf added a commit that referenced this pull request Aug 25, 2022
Replace logging thread for JULI's AsyncFileHandlerwith an executor to
protect against failure of the logging thread.
Based on pull request #545 by Piotr P. Karwasz.
markt-asf added a commit that referenced this pull request Aug 25, 2022
Replace logging thread for JULI's AsyncFileHandlerwith an executor to
protect against failure of the logging thread.
Based on pull request #545 by Piotr P. Karwasz.
markt-asf added a commit that referenced this pull request Aug 25, 2022
Replace logging thread for JULI's AsyncFileHandlerwith an executor to
protect against failure of the logging thread.
Based on pull request #545 by Piotr P. Karwasz.
@markt-asf
Copy link
Contributor

Applied manually so I could address the lost messages on shutdown issue.
Thanks for the PR.

@markt-asf markt-asf closed this Aug 25, 2022
@ppkarwasz ppkarwasz deleted the new-async-file-handler branch August 25, 2022 17:58
@ppkarwasz
Copy link
Contributor Author

@markt-asf, thanks for taking care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants