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

fix(node/readline): hang when closing on STDIN #15628

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

DonIsaac
Copy link
Contributor

@DonIsaac DonIsaac commented Dec 7, 2024

What does this PR do?

Fixes #15344

Calling close on a readline interface (either sync or from readline/promises) was not closing the underlying input. This was causing stdin to re-open, as unpause() was being called between emit("pause") and emit("close")

I'm not quite sure what was causing the segfault, but this fixes that too.

How did you verify your code works?

I've added test cases.

@DonIsaac DonIsaac added bug Something isn't working node:readline labels Dec 7, 2024
@robobun
Copy link

robobun commented Dec 7, 2024

❌ Your commit faab0ab has 12 failures in #7529:

  • test/regression/issue/09041.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 aarch64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64-baseline
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64
  • test/js/third_party/socket.io/socket.io-connection-state-recovery.test.ts - 4 failing on 🐧 22.04 aarch64
  • test/cli/hot/hot.test.ts - timeout on 🐧 24.04 x64-baseline
  • test/cli/hot/hot.test.ts - timeout on 🐧 24.04 x64
  • test/cli/hot/hot.test.ts - timeout on 🐧 3.20 x64-baseline
  • test/cli/hot/hot.test.ts - timeout on 🐧 3.20 x64
  • test/js/third_party/grpc-js/test-outlier-detection.test.ts - 1 failing on 🐧 22.04 aarch64
  • test/integration/next-pages/test/next-build.test.ts - 1 failing on 🐧 24.04 x64
  • test/js/deno/performance/performance.test.ts - 1 failing on 🐧 24.04 x64-baseline
  • test/js/node/http/node-http.test.ts - 1 failing on 🐧 24.04 aarch64
  • test/js/node/http/node-http.test.ts - 1 failing on 🐧 22.04 aarch64
  • test/js/third_party/pino/pino.test.js - incorrect alignment on 🪟 2019 x64
  • test/js/third_party/pino/pino.test.js - segmentation fault at address 0x28dff22b940 on 🪟 2019 x64-baseline
  • test/js/third_party/pino/pino.test.js - segmentation fault at address 0x1bf4994f940 on 🪟 2022 x64-baseline
  • test/js/bun/spawn/spawn-signal.test.ts - 2 failing on 🪟 2025 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🪟 2022 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🪟 2025 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🪟 2019 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🪟 2019 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🪟 2022 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🪟 2025 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🍎 13 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🍎 14 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 11 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 24.04 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 22.04 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 12 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 20.04 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 24.04 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 22.04 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 12 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 11 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 20.04 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 24.04 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 22.04 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 12 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 11 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 20.04 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 3.20 aarch64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🐧 3.20 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🍎 14 x64
  • test/js/third_party/prompts/prompts.test.ts - 1 failing on 🍎 13 x64
  • test/cli/run/require-cache.test.ts - 1 failing on 🪟 2022 x64-baseline
  • test/cli/run/require-cache.test.ts - 1 failing on 🪟 2019 x64-baseline
  • test/cli/run/require-cache.test.ts - 1 failing on 🪟 2019 x64
  • @DonIsaac DonIsaac requested a review from a team December 7, 2024 02:34
    Copy link
    Member

    @paperdave paperdave left a comment

    Choose a reason for hiding this comment

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

    damn

    @Jarred-Sumner
    Copy link
    Collaborator

    I'm confused why a JS-only change could/would fix a segfault

    @Jarred-Sumner
    Copy link
    Collaborator

    interesting

    1 | })
    2 |   let readRequest = @getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests").shift();
                                                                                                          ^
    TypeError: undefined is not an object (evaluating '@getByIdDirectPrivate(@getByIdDirectPrivate(stream, "reader"), "readRequests").shift')
          at handleResult (79:41)
          at promiseReactionJob (45:84)

    Copy link
    Collaborator

    @Jarred-Sumner Jarred-Sumner left a comment

    Choose a reason for hiding this comment

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

    Node's implementation doesn't call close on this.input, and most of readline is copypasta. I think this likely introduces bugs (which is supported by the test failure)

    https://github.com/nodejs/node/blob/9c046ea8042c435d2cbecccbc1a1460630f59c3f/lib/internal/readline/interface.js#L516-L528

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    bug Something isn't working node:readline
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Segfault with readline
    5 participants