fix: preserve explicit priority 0 in facility ordering#22
Open
AI-Reviewer-QS wants to merge 1 commit into
Open
fix: preserve explicit priority 0 in facility ordering#22AI-Reviewer-QS wants to merge 1 commit into
AI-Reviewer-QS wants to merge 1 commit into
Conversation
The facs() method uses `if (!p[5]) p[5] = 1` to assign a default priority to facilities that don't have one. However, `!0` is `true` in JavaScript, so facilities explicitly registered with priority 0 are silently mutated to priority 1. This corrupts the shutdown order: facilities at priority 0 (intended to shut down last) end up sharing priority 1 with other facilities, making teardown ordering between them non-deterministic. Fix all three locations: - facs(): `if (!p[5])` -> `if (p[5] == null)` for default assignment - start(): `f[5] || 0` -> `f[5] ?? 0` for sorting - stop(): `(f[5] || 0) * -1` -> `(f[5] ?? 0) * -1` for reverse sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
facs()treating explicit priority0as unset due to JavaScript falsy semantics (!0 === true)if (!p[5]) p[5] = 1check onbase.js:152mutates facilities registered with priority0to priority1, corrupting the intended startup and shutdown orderingf[5] || 0instart()andstop()sort comparators which have the same issueProblem
When a facility is registered with explicit priority
0viasetInitFacs():The
facs()method mutates priority0to1because!0istruein JavaScript. Afterstart(), the store facility and net facility share the same priority (1), making shutdown order non-deterministic. The intended shutdown order (log -> net -> store) is not guaranteed.Fix
Replace falsy checks with nullish checks:
facs()defaultif (!p[5]) p[5] = 1if (p[5] == null) p[5] = 1start()sortf[5] || 0f[5] ?? 0stop()sort(f[5] || 0) * -1(f[5] ?? 0) * -1Test plan
0is preserved afterfacs()runs