Immediate AFK kick after join in unpredictable circumstances
RoyCurtis opened this issue ยท 2 comments
Uncommonly, a player may get kicked by the AFK timer immediately after logging in. This is a difficult issue as there is no reliable reproduction, as best as I have tried to find one. This is a bug I have observed for at least two years now, spanning Essentials, SpigotEssentials and now EssentialsX.
It is possible that this issue is related to, or a duplicate of, #97.
Details
- Issue observed on:
- Previous servers spanning 1.6.4 to 1.7.10 (no specific details available)
- Spigot 1.8.8 production server,
git-Spigot-db6de12-18fbb24
(2 versions behind), 29 plugins, EssentialsX 2.0.1-b237 - Spigot 1.8.8 local dev server,
2.0.1-b237
(1 version behind), 1 plugin, EssentialsX commit c56dd6e
- Config on:
- Production server
- Local dev server (five second kick for testing purposes)
- For both servers, the vanilla AFK timer (
player-idle-timeout
inserver.properties
) is set to 0 (disabled)
Example
The following happened earlier today. The kick happened almost immediately after the join. It did not repeat when the player relogged in. The last time the player was online was a day prior, and were not AFK kicked that time. Between that time and the log below, the server was restarted once (daily restart).
[00:02:55] NightWorldSky joined the game
[00:02:56] NightWorldSky was kicked from the server: You have been kicked for idling more than 15 minutes.
[00:02:59] NightWorldSky joined the game
Theory
I am unfamiliar with the Essentials codebase. Please excuse any faulty assumptions.
I have a feeling this may be a race condition, brought on by Essentials handling of the PlayerJoinEvent
in an asynchronous task. Async/multi-threaded code can result in unpredictable and difficult to reproduce bugs such as this.
Suggestions
A possible workaround is to make the AFK timer logic enforce a minimum time since player's login, before toggling AFK state or kicking for AFK. In the checkActivity()
function of User.java
, could there be a check like this?
// Do not bother activity checking if player hasn't been online for more than 10 seconds
if (System.currentTimeMillis() - lastOnlineActivity < 10000) { return; }
Such a check would mean auto-afk
and auto-afk-kick
would have an effective minimum of 10 seconds. Subjectively, it would not make sense to have AFK timers that low anyway.
Thank you for setting such a good example of an issue. I've committed your fix (0641791) with the exception that lastActivity is the variable being used as that's what matters to us.
P.S. Why not PR it yourself? :) You seemed to have gone through the trouble of figuring it out all by yourself.
Oh, thanks! I am very grateful for the prompt fix :)
But I should stress the suggestion I made was a shot in the dark (this is why I was hesitant to make a PR). I was not confident if it was even a good suggestion.
I will update to latest commit immediately on our server and monitor it over the next month for this bug.
Thanks again; glad to be of help!