Skip to content

Commit

Permalink
fix: solve an infinite update loop that consumes a core
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Oct 17, 2024
1 parent 4f505ad commit 967cf6e
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public GameTracker(@NotNull MessagingModule messagingModule, @NotNull GameSdkCon

private void maxTimeUpdate(@NotNull Game game) {
long nextExpectedUpdate = game.getLastGameTrackerUpdate() + (this.config.maxTrackingInterval() * 1000L);
if (nextExpectedUpdate < System.currentTimeMillis()) {
long timeUntilNextUpdate = nextExpectedUpdate - System.currentTimeMillis();
if (timeUntilNextUpdate > 0) {
// Game has been updated in the meantime, let's reschedule this task
this.gameMaxTimeUpdateTasks.put(game, SCHEDULER.schedule(() -> {
this.maxTimeUpdate(game);
}, nextExpectedUpdate - System.currentTimeMillis(), TimeUnit.MILLISECONDS));
}, timeUntilNextUpdate + 10, TimeUnit.MILLISECONDS));
return;
}

Expand Down Expand Up @@ -119,10 +120,10 @@ private void onGameUpdateRequest(@NotNull GameUpdateRequestEvent event) {
// Game was updated too recently, queue an update if it isn't already queued

// Schedule an update for the next interval
SCHEDULER.schedule(() -> {
game.markTrackerUpdated();
this.updateGame(game);
}, minNextUpdate - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
SCHEDULER.schedule(
() -> this.updateGame(game),
minNextUpdate - System.currentTimeMillis(),
TimeUnit.MILLISECONDS);
return;
}

Expand Down

0 comments on commit 967cf6e

Please sign in to comment.