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

Debug Console: wrong order of incoming input #33822

Closed
roojay520 opened this issue Sep 5, 2017 · 12 comments
Closed

Debug Console: wrong order of incoming input #33822

roojay520 opened this issue Sep 5, 2017 · 12 comments
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

@roojay520
Copy link

Runtime environment

  • Visual Studio Code v1.15.1 own compiler
  • Node.js v8.2.1
  • OS: Windows_NT ia32 10.0.15063

Description

I want to add "After sort:" between source arry and sort arry, look like this:
CONSOLE Screenshot 1

But console occasionally shows:
CONSOLE Screenshot 2

Why for-of-loop has not finished running, jump out to run console.log ? Source code:

    // Random to generate double digits.
    function getRandom() {
      return Math.round(Math.random() * 100);
    }
    // Writing data to the array.
    var score = [
      ["a", getRandom()],
      ["b", getRandom()],
      ["c", getRandom()],
      ["d", getRandom()],
      ["e", getRandom()]
    ];
    console.log("Before sort:");

    // Print source arry
    for (let m of score) {
      console.log(m);
    }

    // Call sort()
    score.sort((a, b) => {
      return b[1] - a[1];
    });
    console.log("After sort:");

    // Print sort arry.
    for (let n of score) {
      console.log(n);
    }

If i change my code like this:

// Writing data to the array.
var score = [["a", 55], ["b", 33], ["c", 44], ["d", 88], ["e", 22]];
// Print source arry
for (let m of score) {
  console.log(m);
}
console.log("After sort:");

This bug will still appear:
CONSOLE Screenshot 3

@vscodebot vscodebot bot added the debug Debug viewlet, configurations, breakpoints, adapter issues label Sep 5, 2017
@roojay520 roojay520 changed the title A bug in the node-inspector A bug in the JavaScript DEBUG CONSOLE Sep 5, 2017
@isidorn
Copy link
Contributor

isidorn commented Sep 5, 2017

This is just the order the order in which node is emitting events. Not sure if we can do anything here, though assigning to @roblourens since I see you are using the inspector protocol.

@isidorn isidorn assigned roblourens and unassigned isidorn Sep 5, 2017
@roblourens roblourens assigned isidorn and unassigned roblourens Sep 5, 2017
@roblourens
Copy link
Member

The output events come back from the adapter in the right order, but they seem to get reordered by the console when it resolves the variables.

If the log statement is console.log(1) instead of logging an object, then this doesn't repro.

@isidorn
Copy link
Contributor

isidorn commented Sep 6, 2017

I acknowledge the bug, the issue is that vscode gets an object as output from node2. VSCode has to get the children of that object by sending some request to node2. In the meantime more output comes which gets recieved before the children get resolved thus being appended to the output before.

Code pointer

The fix would be to remember the events in which they came and append them to the repl in that order. This has the downside that if some object takes a long time to resolve all subsequent output will be stuck.
Not a big fan of the fix -> backlog

@isidorn isidorn added the bug Issue identified by VS Code Team member as probable bug label Sep 6, 2017
@isidorn isidorn added this to the Backlog milestone Sep 6, 2017
@roojay520
Copy link
Author

Thanks for your answer.

@roblourens
Copy link
Member

Can't the object be inserted in the right position, once it's resolved, while still appending other output?

This seems like a really bad bug - having logs in the wrong order could make someone waste a lot of time debugging.

@isidorn
Copy link
Contributor

isidorn commented Sep 7, 2017

Yes, we could insert it in the right position by changing the appendToRepl API we have in the debugModel.
I would only look into this if more users complain since the model is quite fragile due to various heuristics on spliting incoming output.

@isidorn isidorn changed the title A bug in the JavaScript DEBUG CONSOLE Debug Console: wrong order of incoming input Oct 27, 2017
@good-bits
Copy link

good-bits commented Oct 29, 2017

@isidorn Possibly related to this defect and hopefully helpful: I bumped into an issue where console.log() and console.error() messages consistently appear out of order in the VS Code JavaScript DEBUG CONSOLE. The isolated code below demonstrates the observation. Has NOT been observed outside of the DEBUG CONSOLE (not when running Node.js from the command prompt; not in Chrome web browser). Thanks!

Particulars:

  • Visual Studio Code v1.17.2
  • Node.js v8.5.0
  • Windows 10 v1703, build 15063.674, 64-bit

image

The VS Code DEBUG CONSOLE:

image

@isidorn
Copy link
Contributor

isidorn commented Oct 30, 2017

@good-bits yeah, this seem to be the same issue. Assigning to November to investigate into a fix.

@isidorn isidorn modified the milestones: Backlog, November 2017 Oct 30, 2017
@good-bits
Copy link

@isidorn Thanks!

@weinand
Copy link
Contributor

weinand commented Nov 7, 2017

I agree with Rob that this is really a bad bug that we should fix: logs are for troubleshooting bugs not for making the troubleshooting more difficult...

@isidorn
Copy link
Contributor

isidorn commented Nov 7, 2017

@good-bits I have investigated into your issue and it is actually not the same as the one from above. To be more precise the issue is in the debug adapter - it is sending the events in the wrong order. To track this issue I have created #37770

Keeping this open as this is a different issue explained in my comment above and I will investigate in a fix.

@isidorn isidorn closed this as completed in e741aad Nov 8, 2017
@good-bits
Copy link

@isidorn @roblourens @weinand Thank you so much!

@RMacfarlane RMacfarlane added the verified Verification succeeded label Dec 6, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 23, 2017
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
Development

No branches or pull requests

6 participants