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

Do not pin threads when handling sync metrics #285

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

Floweynt
Copy link
Contributor

@Floweynt Floweynt commented Feb 4, 2025

The current implementation of Metric#collect for non-async-capable metrics is flawed:

Bukkit.getScheduler().callSyncMethod(plugin, () -> {
    try {
        doCollect();
    }
    catch (Exception e) {
        logException(e);
    }
    return null;
}).get();

get() is implemented in Bukkit with Object#wait. It is not advisable to ever call this method from an Executor, since low level synchronization primitives typically pin the thread. For instance, this will cause a deadlock with CommandAPI, since CommandAPI's reloading mechanism will dispatch some tasks to ForkJoinPool.commonPool(). In the case that all threads are pinned by this plugin, CommandAPI never finishes reloading datapacks and thus blocks the main thread forever (which means callSyncTask's future never completes).

Instead of waiting, we can simply construct a CompletableFuture which is completed whenever the metric is done collecting.

@sladkoff sladkoff merged commit db32332 into sladkoff:master Feb 11, 2025
1 check passed
@sladkoff sladkoff added this to the 3.1.1 milestone Feb 11, 2025
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.

2 participants