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

Wrong order of incoming input from adapter #37770

Closed
isidorn opened this issue Nov 7, 2017 · 2 comments · May be fixed by maxemiliang/vscode-ext#31 or stefanonepa/vscode-chrome-debug#5
Closed

Wrong order of incoming input from adapter #37770

isidorn opened this issue Nov 7, 2017 · 2 comments · May be fixed by maxemiliang/vscode-ext#31 or stefanonepa/vscode-chrome-debug#5
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Milestone

Comments

@isidorn
Copy link
Contributor

isidorn commented Nov 7, 2017

Originaly reported by @good-bits
I can repro both with node2 and node debug adapter
I tried with node 7.9, os x

Have the following node program, notice how the output is coming wrongly ordered from the debug adapter:

for (var i =0; i < 20; i++) {
    console.log('log : ' + i);
    console.error('error : ' + i);
}

Code pointer where output is recieved on the vscode side.

@isidorn isidorn added bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues labels Nov 7, 2017
@weinand
Copy link
Contributor

weinand commented Nov 7, 2017

Running the program in VS Code results in this output on the debug console:
2017-11-07_12-44-56

If you run the program from a terminal you get this:
2017-11-07_12-47-24

This discrepancy is expected. Here is the explanation:

Node.js tries to detect whether its stdout and stderr streams are connect to a line-oriented device (like a terminal) or to a block oriented device (e.g a file).
In the former case it assumes that a user is running the node program interactively and node flushes buffered "log" or "error" data after one line. As a result the "log" or "error" output appears alternating.
For block oriented devices more data is buffered until it is flushed.

By default VS Code launches node.js programs for the "Debug Console" in a way that uses block oriented streams. That explains the multi-line buffering which results in the unexpected ordered output.

To fix this, you can set the console attribute of a launch configuration to either integratedTerminal or externalTerminal. In this case a line oriented output device is used which results in ordered output.

@weinand weinand added the *as-designed Described behavior is as designed label Nov 7, 2017
@weinand weinand closed this as completed Nov 7, 2017
@roblourens
Copy link
Member

roblourens commented Nov 7, 2017

True when reading from stdout/err, but there is a bug here in node2 getting messages from the debug protocol. It's in the correct order in chrome devtools. Error messages will be delayed because of this line: https://github.com/Microsoft/vscode-chrome-debug-core/blob/master/src/chrome/chromeDebugAdapter.ts#L896 and will end up out of order. This code needs to handle only one message at a time.

@roblourens roblourens reopened this Nov 7, 2017
@roblourens roblourens added this to the November 2017 milestone Nov 7, 2017
@roblourens roblourens removed the *as-designed Described behavior is as designed label Nov 7, 2017
@isidorn isidorn added the verified Verification succeeded label Dec 5, 2017
roblourens added a commit to microsoft/vscode-node-debug2 that referenced this issue Dec 24, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Projects
None yet
3 participants