Skip to content

[windows] [readline] [https] Closing input halts event loop #21771

Description

@coolaj86
  • Version: 10.2.1, 10.6.0
  • Platform: Windows 7, Windows 10
  • Subsystem: readline https

It turns out that if you have readline open as a terminal, ask a question, make an http request, then close readline, the even loop appears to halt on the next http request.

No error. No timeout. Just sits there for minutes or hours or days.

Does not affect Mac or Linux, just Windows.

Took me a few hours of debugging over a few days to figure out that I wasn't doing anything wrong in my code and then reduce it down far enough to produce an isolated test case that proves I'm not going insane. :)

'use strict';

var https = require("https");
var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin
, output: process.stdout
  // Setting explicitly due to https://github.com/nodejs/node/issues/21319
  // however, on windows it is being run directly
, terminal: true
});

rl.question('Type anything: ', makeRequests);

function makeRequests() {

  var req = https.request('https://telebit.cloud/_apis/telebit.cloud/index.json', function (resp) {
    console.log("ONE response received");

    resp.on('data', function () {
      console.log("ONE got some data");
    });
    resp.on('end', nextRequest);

    function nextRequest() {
      console.log("ONE completed the request");
      rl.close();
      console.log("closed the readline");

      var req = https.request('https://telebit.cloud/_apis/telebit.cloud/index.json', function (resp) {
        console.log("TWO response received");
        resp.on('data', function () {
          console.log("TWO got some data");
        });
        resp.on('end', function () {
          console.log("TWO completed the request");
        });
      });
      req.on('error', function (err) {
        console.error(err);
      });
      req.end();

      //
      // TESTING THE EVENT LOOP
      //
      console.log("(before loop is checked)");
      process.nextTick(function () {
        console.log("(same loop)"); // never shows
      });
      setTimeout(function () {
        console.log("(future loop)"); // never shows
      }, 100);
    }

  });
  req.on('error', function (err) {
    console.error(err);
  });
  req.end();

}

Possibly related bugs

Possible workarounds

  • Explicitly set terminal: false
  • Don't call rl.close()

Activity

  1. changed the title [-][windows] [readline] [https] Closing input causes requests to freeze[/-] [+][windows] [readline] [https] Closing input halts event loop[/+] on Jul 11, 2018
  2. bzoz commented on Jul 12, 2018

    @bzoz
    Contributor

    Cannot reproduce on 10.6.0

  3. bzoz commented on Jul 12, 2018

    @bzoz
    Contributor

    Hm.. while I get those (same loop) and (future loop) messages, Node does not exit until I hit enter.

  4. coolaj86 commented on Jul 12, 2018

    @coolaj86
    Author

    @bzoz What OS and version of OS are you on?

    Also, do you ever see "TWO completed the request"?

  5. bzoz commented on Jul 12, 2018

    @bzoz
    Contributor

    Win10 17134.165

  6. bzoz commented on Jul 12, 2018

    @bzoz
    Contributor

    @coolaj86, are you maybe using ConEmu or some other console emulator?

  7. totomz commented on Nov 16, 2018

    @totomz

    Windows Server 2016 Datacenter v1607 is also affected, with node v10.13.0 and 11.2, on both commdand prompt and powershell

    Both the suggested workarounds fix this issue

  8. added a commit that references this issue on Nov 16, 2018
  9. added
    windowsIssues and PRs related to the Windows platform.
    readlineIssues and PRs related to the built-in readline module.
    httpsIssues and PRs related to the https subsystem.
    on Nov 29, 2018
  10. added
    streamIssues and PRs related to Node.js streams.
    on Dec 14, 2019
  11. BridgeAR commented on Dec 14, 2019

    @BridgeAR
    Member

    @ronag this seems streams related and I guess you might want to have a look at this.

  12. ronag commented on Dec 20, 2019

    @ronag
    Member

    @BridgeAR I wouldn't mind looking into this but I don't have a Windows setup anymore. Any advice in regards to how to have a virtual setup? Is there a any online service which could just give me a e.g. a ssh to windows machine?

  13. Hakerh400 commented on Dec 20, 2019

    @Hakerh400
    Contributor

    @ronag I can provide you a virtual machine (VirtualBox or VMWare) with Windows operating system installed (I have almost any Windows version from Windows 95 to the latest Windows 10). Just let me know which Windows version you want and how much RAM and HDD space the virtual machine should have so that you can run it smoothly on your system.

  14. ronag commented on Dec 20, 2019

    @ronag
    Member

    @Hakerh400: Much appreciated! A Windows 10 with 1G ram and 64 GB HDD should be enough.

  15. Hakerh400 commented on Dec 20, 2019

    @Hakerh400
    Contributor

    Windows10.zip

    Username: user
    Password: pass

  16. tjhiggins commented on May 22, 2020

    @tjhiggins

    +1 - Still an issue on node v12.16.3/Windows 10/Powershell

  17. chengzhuo5 commented on Aug 16, 2020

    @chengzhuo5

    #30701
    Node 14.6 has fixed this problem.

  18. huseyinacacak-janea commented on Sep 4, 2024

    @huseyinacacak-janea
    Contributor

    I've investigated this issue with Node v18.20.2, v20.16.0 and v22.7.0. All of them worked as expected.
    @coolaj86 Do you think this can be closed as this issue is now fixed in the current versions of Node?

  19. avivkeller commented on Sep 4, 2024

    @avivkeller
    Member

    Per the comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpsIssues and PRs related to the https subsystem.readlineIssues and PRs related to the built-in readline module.streamIssues and PRs related to Node.js streams.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions