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

Fix plugin loggers on shutdown #5592

Merged
merged 7 commits into from
Aug 21, 2022

Conversation

josemmo
Copy link
Contributor

@josemmo josemmo commented May 8, 2021

When system property "terminal.jline" is false and the server receives a SIGINT/SIGTERM plugin, non-root loggers did not work due to how shutdown hooks work.

@josemmo josemmo requested review from a team as code owners May 8, 2021 14:11
Copy link
Contributor

@Proximyst Proximyst left a comment

Choose a reason for hiding this comment

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

warning: sun.misc.SignalHandler is Sun proprietary API and may be removed in a future release

Dunno if we want to rely on this...

@electronicboy
Copy link
Member

that API has been around for a loooong time, I can't really see something getting rid of it on the basis that it's the only way to actually hook into these signals afaik, I can't see this getting stripped out any time soon

@electronicboy
Copy link
Member

I'm assuming that you've tested that this doesn't bork anything when ran with/without jline?

@Shevchik
Copy link
Contributor

Shevchik commented May 8, 2021

The attempt to init signal handler should be wrapped in try-catch then, just in case.

@josemmo
Copy link
Contributor Author

josemmo commented May 9, 2021

@electronicboy
I'm assuming that you've tested that this doesn't bork anything when ran with/without jline?

Tested on Java 8 with nogui (JLine enabled) and --nojline nogui (JLine disabled), and stopping server using the /stop command and sending CTRL+C keyboard combination.

With JLine enabled the stop signal handler doesn't get called as JLine intercepts the program input.


@electronicboy
that API has been around for a loooong time, I can't really see something getting rid of it on the basis that it's the only way to actually hook into these signals afaik, I can't see this getting stripped out any time soon

Just created a simple project with JDK 16 and "sun.misc.*" is still there. It is also available in the internal "jdk.internal.misc.*" package. In the wost case scenario this package can be exposed with --add-exports.


@Proximyst
Dunno if we want to rely on this...

If hooking into internal APIs is an issue the other alternative is to hijack the app log manager and override the reset() method, which is the one responsible for loggers not working on shutdown:

System.setProperty("java.util.logging.manager", CustomLogManager.class.getName());

public static class CustomLogManager extends LogManager {
    // [...]
    @Override
    public void reset() {
        // Ignore method call if still shutting down
        // [...]
    }
}

@kashike
Copy link
Member

kashike commented May 10, 2021

@A248
Copy link
Contributor

A248 commented May 12, 2021

warning: sun.misc.SignalHandler is Sun proprietary API and may be removed in a future release

If there's a warning about it, that seems reason enough to avoid it. In JDK 16 there is also Strongly Encapsulate JDK Internals by Default. Now is definitely not the time to regress back to depending on internals.

@josemmo
Copy link
Contributor Author

josemmo commented May 15, 2021

Ok, I guess the consensus here is to avoid using signal handlers.
Should I update the PR to fix #5270 by hijacking the log manager then?

@josemmo
Copy link
Contributor Author

josemmo commented May 22, 2021

Just pushed a new patch that uses the custom log manager approach instead of signal handlers.

Copy link
Contributor

@Proximyst Proximyst left a comment

Choose a reason for hiding this comment

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

Clean! Nice!

- Added stop signal listener to MinecraftServer

> When system property "terminal.jline" is false and the server receives a SIGINT/SIGTERM plugin, non-root loggers did not work due to how shutdown hooks work.
- Removed patch for PaperMC#5270 that used signal handlers (4dd4295)
- Created custom log manager to ignore calls to CustomLogManager#reset() before server has shutdown

> When system property "terminal.jline" is false and the server receives a SIGINT/SIGTERM plugin, non-root loggers did not work due to how shutdown hooks work.

Fixes PaperMC#5270
- Renamed com.destroystokyo.paper.log.CustomLogManager to io.papermc.paper.log.CustomLogManager
- Updated patch number
@josemmo
Copy link
Contributor Author

josemmo commented Jun 4, 2021

Had to rebase due to a mistype... 🤦‍♂️
Anyway, the custom logger class FQN now is io.papermc.paper.log.CustomLogManager.

Copy link
Contributor

@A248 A248 left a comment

Choose a reason for hiding this comment

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

More of a question than a comment.

- Used string literal when setting "java.util.logging.manager" property
@stale
Copy link

stale bot commented Aug 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot removed the resolution: stale label Aug 21, 2021
@Machine-Maker Machine-Maker added the status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. label Aug 21, 2021
@AwesomeDude091
Copy link

Could this be looked at again?

@electronicboy electronicboy self-assigned this Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable plugins when shutting down server using SIGTERM/SIGINT