Skip to content

chore(cli-repl): try to fix flaky connection string prompt test - #2513

Merged
addaleax merged 1 commit into
mainfrom
try-fix-flaky-connection-string-prompt
Aug 4, 2025
Merged

chore(cli-repl): try to fix flaky connection string prompt test#2513
addaleax merged 1 commit into
mainfrom
try-fix-flaky-connection-string-prompt

Conversation

@addaleax

@addaleax addaleax commented Aug 4, 2025

Copy link
Copy Markdown
Collaborator

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.

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.
Copilot AI review requested due to automatic review settings August 4, 2025 11:39
@addaleax
addaleax requested a review from a team as a code owner August 4, 2025 11:39
@addaleax addaleax added the no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion) label Aug 4, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 wroteAnyKeyToExit is inconsistent with the existing pattern. Consider renaming to wroteAnyKey to match the pattern of wroteConnectionString.
    let wroteAnyKeyToExit = false;

@gagik gagik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, a very subtle thing. Hopefully it fully solves this.

@addaleax
addaleax merged commit c4f7a0a into main Aug 4, 2025
128 of 140 checks passed
@addaleax
addaleax deleted the try-fix-flaky-connection-string-prompt branch August 4, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants