chore(cli-repl): try to fix flaky connection string prompt test - #2513
Merged
Conversation
Currently, in CI we receive errors like
1) CLI entry point
asks for connection string when configured to do so:
Uncaught Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:161:15)
at writeGeneric (node:internal/stream_base_commons:152:3)
at Socket._writeGeneric (node:net:958:11)
at Socket._write (node:net:970:8)
at writeOrBuffer (node:internal/streams/writable:572:12)
at _write (node:internal/streams/writable:501:10)
at Socket.Writable.write (node:internal/streams/writable:510:10)
at Socket.<anonymous> (Z:\data\mci\e6e6\src\packages\cli-repl\src\run.spec.ts:87:20)
at Socket.emit (node:events:524:28)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Socket.Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)
at Pipe.callbackTrampoline (node:internal/async_hooks:130:17)
(e.g. https://spruce.mongodb.com/task/mongosh_tests_win32_m50xc_n20_test_cli_repl_patch_7fa888fae7921991c99175aad0ebba46751c2954_68907a2301ef2900071ba30e_25_08_04_09_15_17/logs).
The hypothesis here is that the following sequence of events occurs:
1. The test runs normally up to the point where the application prompts
for `Press any key to exit`.
2. The test reads that text from the application and sends and `x` key
to the mongosh process.
3. The mongosh process reads the `x` key and echoes it back to the terminal
(since it is in raw mode).
4. The mongosh process exits (the test passes if this happens *after* the
next steps, which is where the flakiness of the test may come from).
5. The test reads the `x` key echoed back in step 3 and, seeing more
output coming from mongosh, *repeats* step 2, since its condition
is still met.
6. Sending the second `x` key to the process fails with `EPIPE` because the
target process has already exited.
Sending the `x` key only once should resolve the flakiness, if this is
indeed what happens.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a flaky test in the CLI REPL component by preventing duplicate key writes to an already exited process. The issue was that the test would sometimes send an 'x' key twice to the mongosh process when prompted to "Press any key to exit", causing the second write to fail with EPIPE after the process had already terminated.
- Introduces a flag to track whether the "any key to exit" response has been sent
- Modifies the condition to only send the 'x' key once when the exit prompt appears
Comments suppressed due to low confidence (1)
packages/cli-repl/src/run.spec.ts:77
- [nitpick] The variable name
wroteAnyKeyToExitis inconsistent with the existing pattern. Consider renaming towroteAnyKeyto match the pattern ofwroteConnectionString.
let wroteAnyKeyToExit = false;
gagik
approved these changes
Aug 4, 2025
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.
Currently, in CI we receive errors like
(e.g. https://spruce.mongodb.com/task/mongosh_tests_win32_m50xc_n20_test_cli_repl_patch_7fa888fae7921991c99175aad0ebba46751c2954_68907a2301ef2900071ba30e_25_08_04_09_15_17/logs).
The hypothesis here is that the following sequence of events occurs:
Press any key to exit.xkey to the mongosh process.xkey and echoes it back to the terminal (since it is in raw mode).xkey echoed back in step 3 and, seeing more output coming from mongosh, repeats step 2, since its condition is still met.xkey to the process fails withEPIPEbecause the target process has already exited.Sending the
xkey only once should resolve the flakiness, if this is indeed what happens.