Fabric API

Fabric API

111M Downloads

`ServerLifecycleEvents` documentation does not indicate it will not be triggered after datagen.

solonovamax opened this issue ยท 0 comments

commented

Copying this over from FabricMC/fabric-loom#1145 because I accidentally opened the issue on the wrong repo. (oopsies)

Issue

Unclear documentation in ServerLifecycleEvents causes events to be misappropriately used in certain scenarios.

When using datagen in a dev env, ServerLifecycleEvents are not triggered.

This can cause issues with mods/apis that, for example, rely on ServerLifecycleEvents.SERVER_STOPPING to clean up some resources.

As an example, I ran into this issue with AzureDoom/AzureLib#62, where a thread executor is spawned in non-daemon mode, and will be closed down when the ServerLifecycleEvents.SERVER_STOPPING event is emitted.
However, since it is never emitted, this causes the datagen to never exit, as the jvm sees that there's an active thread that is not marked as a daemon thread.

Should ServerLifecycleEvents.SERVER_STOPPING be emitted when the datagen finishes, or should it be added to the docs to not use it for cleaning up resources, as it can fail during datagen?


Proposed Solution

Documentation for SERVER_STOPPING and SERVER_STOPPED should be updated to mention

it is recommended that this event only be used for cleaning up resources that are created during SERVER_STARTING and SERVER_STARTED.
This event will not be emitted when using datagenning, and thus should be avoided by libraries for cleaning up resources (such as thread pools, databases, etc.) that were not started during SERVER_STARTING or SERVER_STARTED, as it will cause them to not get cleaned up.