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

Pasting code into node repl makes it exit on Windows #21773

Closed
pps83 opened this issue Jul 11, 2018 · 21 comments
Closed

Pasting code into node repl makes it exit on Windows #21773

pps83 opened this issue Jul 11, 2018 · 21 comments
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform.

Comments

@pps83
Copy link

pps83 commented Jul 11, 2018

Node v8.11.2
Win10 Pro

I run node from cmd.exe, and simply paste this code using r-click:

var crypto = require('crypto');
function hmacN(N)
{
    console.log(N);
}

The moment I paste it, node exists and I get this output:

Microsoft Windows [Version 10.0.17134.81]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\username>node
> var crypto = require('crypto');
undefined
> function hmacN(N)
... {
...     console.log(N);
... }
undefined
>
C:\Users\username>

This used to work properly (e.g. it shouldn't exit), that's how I always test snippets by pasting them into node-repl console.

Interesting observation: if I paste incomplete code (without last }) then it won't exit and I need to manually complete it with the last brace and can continue. Or, if pasted block doesn't end with a new line character, then it will also won't exist and will wait for manual [ENTER] key press. Also, to confirm, the problem happens on 8.11.3 as well

@bzoz
Copy link
Contributor

bzoz commented Jul 12, 2018

I cannot reproduce this. Are you using any console emulator like ConEmu?

@pps83
Copy link
Author

pps83 commented Jul 12, 2018

No, I use regular cmd.exe, plain vanilla win10 pro.

I tried to do the same on my home PC and I don't have that problem. What could possibly make it fail on my other PC?

@lundibundi
Copy link
Member

@pps83 could you please

  • tell where are you copying the code from?
  • try to type the code in some plain editor like notepad and copy it from there?

This will allow to check the case when app you are copying from adds some additional characters (like Enter,Ctrl+d that will result in this behavior).

Also could you also check if it affects latest node? (10.7.0 at a time of writing).

@pps83
Copy link
Author

pps83 commented Jul 26, 2018

I use awesome notepad++, so it's plain text.
current 10.0.7 has identical problem for me. I have a guess of what might be happening. Could it be that pasted text ends up with unix-style line endings ('\n' instead of '\r\n')? I'm connected from a mac and I RDP to Windows box where I work. I also tried to connect using teamviewer and I had identical problem. Perhaps, when text Ctrl+C'opied it gets converted to mac-style line endings in the buffer? That's the only guess I have.

However, I also RDP to this windows from another windows PC (with no Mac involved at all) and I end up with the same problem.

@vuGitH
Copy link

vuGitH commented Aug 27, 2018

I have exactly the same problem. Independently from where I have copied a text from notepad++ or from this thread getting your piece of code literally the nodejs throws me out of REPL into w10 command prompt.

@vuGitH
Copy link

vuGitH commented Aug 27, 2018

@pps83 There is not a solution but temporal remedy:
I used .editor command then pasted a snippet and typed ^D. The output is as follows:
(first goes an attempt without .editor then with it)

I:\nodejs>node
> var crypto = require('crypto');
undefined
> function hmacN(N)
... {
...     console.log(N);
... }
undefined
>
I:\nodejs>node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
var crypto = require('crypto');
function hmacN(N)
{
    console.log(N);
}

undefined
> hmacN(10)
10
undefined
>

This works for me. Try it on your PC.

@vuGitH
Copy link

vuGitH commented Aug 27, 2018

Another option:

  • Open cmd.exe.
  • Press Alt + Space, then P key;
  • in Options Tab enable "Use legacy console (requires relaunch)" checkbox; press OK
  • relaunch cmd.exe
    try to paste.

@jordanbtucker
Copy link

I'm having this issue too.

  • Windows 10.0.17134.228
  • Node.js v8.11.4

Both in PowerShell and CMD.

It seems to only happen when more than one line break is in the pasted text. For example, pasting the following code will not cause the REPL to exit.

console.log('line 1') // <- there is a line break here

And here's the output.

C:\Users\Jordan>node
> console.log('line 1')
line 1
undefined
> _

However, this code will cause the REPL to exit.

console.log('line 1')
console.log('line 2') // <- there is a line break here

And here's the output.

C:\Users\Jordan>node
> console.log('line 1')
line 1
undefined
> console.log('line 2') // <- there is a line break here
line 2
undefined
>
C:\Users\Jordan>_

@vuGitH's .editor workaround does prevent the REPL from exiting when pressing CTRL+D after pasting the code. Here's that output.

C:\Users\Jordan>node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
console.log('line 1')
console.log('line 2') // <- there is a line break here

line 1
line 2
undefined
> _

@jordanbtucker
Copy link

I just tried this on another computer running Windows 10.0.16299.547 and Node.js v8.11.4 and it did not exhibit this problem.

Then I tried it on another computer running Windows 10.0.17134.228 and Node.js v8.11.3 and it did exhibit the problem. So maybe something changed in Windows that's contributing to this bug.

@vuGitH
Copy link

vuGitH commented Sep 10, 2018

@jordanbtucker Jordan! Thank you for feedback!

@bzoz
Copy link
Contributor

bzoz commented Sep 11, 2018

It also reproduces on my box

@bzoz bzoz added confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform. labels Sep 11, 2018
@bzoz
Copy link
Contributor

bzoz commented Sep 11, 2018

Can be reproduced by:

require('repl').start({
  breakEvalOnSigint: true
});

Switching breakEvalOnSigint to false makes the problem go away.

/cc @nodejs/platform-windows @nodejs/repl

@addaleax
Copy link
Member

I assume the key question here is why the process exits, right? Has anybody been able to figure out whether that is because of an emtpy event loop or because of an explicit exit() call somewhere?

@tniessen
Copy link
Member

@addaleax Yes, the loop is empty (uv_loop_alive returns false), but I am not sure why.

@seishun
Copy link
Contributor

seishun commented Sep 11, 2018

Can anyone reproduce this on Windows 7?

@bzoz
Copy link
Contributor

bzoz commented Sep 11, 2018

Does not reproduce on win7 on my VM.

@bzoz
Copy link
Contributor

bzoz commented Sep 11, 2018

Setting the console back into raw mode (https://github.com/nodejs/node/blob/master/lib/repl.js#L338) triggers this.

@bzoz
Copy link
Contributor

bzoz commented Sep 13, 2018

This can also be triggered by:

process.stdin.on('data', () => {
  process.stdin.setRawMode(true);
  process.stdin.setRawMode(false);
});

and writing something to stdin.

@seishun
Copy link
Contributor

seishun commented Sep 16, 2018

Yes, the loop is empty (uv_loop_alive returns false), but I am not sure why.

Because the call to uv_tty_read_stop failed when calling uv_tty_set_mode with UV_TTY_MODE_NORMAL, consequently uv_tty_read_start wasn't called. setRawMode returned an error code, but it's ignored on JS side.

uv_tty_read_stop failed because the call to WriteConsoleInputW failed with ERROR_INVALID_PARAMETER. Perhaps Windows 10 no longer supports writing bullshit events.

Things to do:

  • Come up with a simple test case and submit an issue in the libuv repo.
  • Improve error handling for setRawMode on Node.js side.

bzoz added a commit to JaneaSystems/libuv that referenced this issue Sep 17, 2018
New Windows version requires `EventType`to be set to something
meaningful, otherwise WriteConsoleInputW will fail with
`ERROR_INVALID_PARAMETER`. This sets it to `FOCUS_EVENT` which
is ignored by `uv_process_tty_read_raw_req`.

Ref: nodejs/node#21773
@bzoz
Copy link
Contributor

bzoz commented Sep 17, 2018

PR with libuv fix: libuv/libuv#1989

danbev pushed a commit that referenced this issue Sep 19, 2018
PR-URL: #22886
Refs: #21773
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
targos pushed a commit that referenced this issue Sep 20, 2018
PR-URL: #22886
Refs: #21773
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@cjihrig
Copy link
Contributor

cjihrig commented Sep 26, 2018

Reopening until the next libuv update.

@cjihrig cjihrig reopened this Sep 26, 2018
cjihrig added a commit to cjihrig/node that referenced this issue Oct 8, 2018
@Trott Trott closed this as completed in c65a523 Oct 9, 2018
targos pushed a commit that referenced this issue Oct 10, 2018
PR-URL: #23336
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Fixes: #23043
Fixes: #21773
Fixes: #16601
Fixes: #22999
Fixes: #23219
Fixes: #23066
Fixes: #23067
Fixes: #23089
jasnell pushed a commit that referenced this issue Oct 17, 2018
PR-URL: #23336
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Fixes: #23043
Fixes: #21773
Fixes: #16601
Fixes: #22999
Fixes: #23219
Fixes: #23066
Fixes: #23067
Fixes: #23089
MylesBorins pushed a commit to MylesBorins/node that referenced this issue Nov 5, 2018
PR-URL: nodejs#23336
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Fixes: nodejs#23043
Fixes: nodejs#21773
Fixes: nodejs#16601
Fixes: nodejs#22999
Fixes: nodejs#23219
Fixes: nodejs#23066
Fixes: nodejs#23067
Fixes: nodejs#23089
MylesBorins pushed a commit that referenced this issue Nov 11, 2018
Backport-PR-URL: #24103
PR-URL: #23336
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Fixes: #23043
Fixes: #21773
Fixes: #16601
Fixes: #22999
Fixes: #23219
Fixes: #23066
Fixes: #23067
Fixes: #23089
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants