Skip to content

Fix client hang on shutdown from non-daemon thread pools - #82

Open
deanxbox wants to merge 1 commit into
FrozenBlock:26.2from
deanxbox:26.2
Open

Fix client hang on shutdown from non-daemon thread pools#82
deanxbox wants to merge 1 commit into
FrozenBlock:26.2from
deanxbox:26.2

Conversation

@deanxbox

Copy link
Copy Markdown

Fixes #79

Problem

Quitting the game leaves the process alive until vanilla's
ClientShutdownWatchdog times out and dumps a crash report. The report is
misleading — there's no exception, just a java.lang.Error: Watchdog (Client shutdown from post-main) about 15 seconds after Stopping!, with the thread
dump showing nothing obviously wrong.

Cause

Two API paths call Executors.newCachedThreadPool():

  • CapeUtil.registerCapesFromURL
  • ModResourcePackApi pack downloading

newCachedThreadPool() uses Executors.defaultThreadFactory(), which creates
non-daemon threads, and keeps each idle worker alive for a 60 second
keepalive after its task completes. Non-daemon threads block JVM exit, so if
you quit within that window the process just sits there until the watchdog
fires.

It also allocates an entirely new pool per call rather than reusing one.

Fix

Both now use Util.nonCriticalIoPool() — vanilla's shared, daemon-backed pool,
already used elsewhere in this repo (ServerTextureDownloader). .forName(...)
tags the worker so it stays readable in thread dumps.

-			Executors.newCachedThreadPool()
+			Util.nonCriticalIoPool().forName("registerCapesFromURL")

Cape repo registration and mod resource pack downloading each called
Executors.newCachedThreadPool(), which spawns non-daemon threads that
linger for a 60s keepalive after their task finishes. Those threads keep
the JVM alive past "Stopping!", so ClientShutdownWatchdog eventually
fires and reports a crash on quit.

Both now use Util.nonCriticalIoPool(), the shared daemon-backed vanilla
pool already used by ServerTextureDownloader. This also stops allocating
a brand new pool on every call.

Also drops two unused imports that were failing checkstyleMain.

Fixes FrozenBlock#79
@deanxbox

Copy link
Copy Markdown
Author

Could we please get this merged in ? if it looks good

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.

1 participant