fantasycalendar / FoundryVTT-Sequencer

This module implements a basic pipeline that can be used for managing the flow of a set of functions, effects, sounds, and macros.
Other
41 stars 17 forks source link

[BUG] - `game.settings.set` `welcome-shown` can happen before `game.ready` #229

Closed rikmarais closed 3 weeks ago

rikmarais commented 3 weeks ago

Describe the bug A race condition can cause game.settings.set("sequencer", "welcome-shown", true) to error and not update the setting, which causes the Sequencer welcome message to be displayed every time a GM logs in.

Relates to code around https://github.com/fantasycalendar/FoundryVTT-Sequencer/blob/master/src/module.js#L148

In Foundry, a world level setting cannot be set if the game is not ready. It is possible for the sequencer.ready hook to be called before the ready hook (before game.ready), possibly due to it being hooked onto multiple triggers, possibly due to network conditions or other factors not commonly encountered in a self-hosting environment.

To Reproduce Difficult to reproduce, due to race condition. Requires a large world and specific network conditions.

Expected behavior game.settings.set("sequencer", "welcome-shown", true) should happen after game.ready.

If game.ready is false at https://github.com/fantasycalendar/FoundryVTT-Sequencer/blob/master/src/module.js#L148, there could be a Hooks.once('ready', ()=> ...) to schedule the settings.set to happen only after the ready hook has fired, ensuring Foundry

Screenshots image

image

image

image

Setup:

Active modules:

Additional context This issue was reported to Forge support. On Forge on small worlds, game.ready is true when game.settings.set is called, and there is no issue. On Forge on a specific user's pf2e world which has a fair amount of data, the race condition was observed.

I believe https://github.com/fantasycalendar/FoundryVTT-Sequencer/commit/604256820c2b3f933489d402e531b6ebfb139684 was implemented as a fix, but I suspect that async/await is not the issue, and I wanted to bring the game.ready behaviour I saw while investigating to your attention.

That said, the user who was encountering this before said that their issue was resolved in 3.2.1, so it might be possible that I am mistaken. If that is the case, please accept my apologies and feel free to close the issue!

console-export-2024-6-18_0-54-43.txt

Haxxer commented 3 weeks ago

Thanks for the detailed breakdown, fixed in 3.2.2