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

Use breadth first flattening order for stages (take 2) #920

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

kalilsn
Copy link
Member

@kalilsn kalilsn commented Feb 3, 2025

Issue(s) Resolved

Resolves #888 and fixes the bug that led to reverting in #917

High-level Explanation of PR

I added one new condition to the body of the loop to prevent infinite loops when the graph has a cycle. I've also added a 500ms timeout to the sorting function after which it just returns the deduped but unsorted stage list, in case there are other bugs and to make sure the app behaves reasonably with communities that have an unreasonable number of stages.

while (stagesQueue.length > 0) {
if (Date.now() - startTime > 500) {
throw new Error("Stage sorting timed out");
}
Copy link
Member Author

@kalilsn kalilsn Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only reliable way to make sure this loop stops after a set amount of time. I'd rather trust some other kind of global timeout but AFAIK that's not really possible in node. Let me know if that's wrong and there's some other technique we can use to set an enforceable global timeout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah i think this is fine! i was initially thinking "couldn't you use a settimeout for this?", but that will never resolve before the while loop is done, something something microtask queue something something event loop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something something microtask queue something something event loop

yeah this is what I meant to say. i am curious if using worker threads and/or some kind of process/fork based server would help with this in production? is that even feasible with next? i doubt this is the last time i'll accidentally add an infinite loop (or really any cpu intensive code) and i would rather not need to have timeout logic all over the app if possible!

Copy link
Contributor

@allisonking allisonking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really appreciate the comments + tests!!

@kalilsn kalilsn enabled auto-merge (squash) February 4, 2025 14:55
@kalilsn kalilsn merged commit 09e2cbe into main Feb 4, 2025
6 checks passed
@kalilsn kalilsn deleted the kalilsn/fix-flattening branch February 4, 2025 15:01
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.

Workflow display out of order when workflow has circular branch
3 participants