Skip to content

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

@coolaj86

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpsIssues or PRs related to the https subsystem.readlineIssues and PRs related to the built-in readline module.streamIssues and PRs related to the stream subsystem.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