Skip to content

Conversation

@younes-io
Copy link
Collaborator

@younes-io younes-io commented Nov 26, 2025

  • Problem: SANY can exit instantly; we ended the merged output stream immediately, so late-attaching listeners missed the end event and Mocha waited 10 seconds then failed
  • Fix: if the process is already exited, defer mergedOutput.end() with setImmediate, giving listeners one tick to subscribe before the end event fires

src/tla2tools.ts Outdated
process.once('close', endMerged);
// If process already exited, end stream now (calling end() twice is safe)
// If the process already exited before listeners are attached, end the merged
// stream on the next tick so late subscribers still observe the `end` event.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by "next tick"?

Copy link
Collaborator Author

@younes-io younes-io Nov 26, 2025

Choose a reason for hiding this comment

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

in the Nodejs the terminology: a "tick" is one complete iteration of the event loop (Timers => Poll => Check)

We use setImmediate to defer execution to the "Check" phase of the loop (unlike process.nextTick which runs immediately). This guarantees the current synchronous stack finishes — allowing the listener to attach — before the event is actually emitted.

for reference https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#processnexttick-vs-setimmediate

Copy link
Member

Choose a reason for hiding this comment

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

This explanation is really helpful. I suggest incorporating it into the comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alright, just pushed a commit

@younes-io younes-io marked this pull request as ready for review November 26, 2025 15:44
@younes-io younes-io self-assigned this Nov 26, 2025
Signed-off-by: Y <[email protected]>
@younes-io younes-io merged commit 949499e into tlaplus:master Nov 26, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants