Skip to content

node protocol probing confuses electron #20301

Closed

Description

@weinand

Observe: a debug session starts and if you set a breakpoint the program will stop and hit the breakpoint.

  • stop session
  • change protocol to auto
  • attach VS Code again

Observe: a message "Debugging with legacy protocol because Node version could not be determined." shows up in the debug console but no debug session starts.

Turning on tracing sends this to the debug console:

Debugging with legacy protocol because Node version could not be determined.
62796: _attach: address: 127.0.0.1 port: 6009
62796: _attach: connected
62796: _terminated: socket end
62796: _terminated: node v8protocol close
62796: _terminated: socket error
62796: _terminated: node v8protocol error
62796: _terminated: node v8protocol error
62796: disconnectRequest: send response

So it looks like that the probing leaves the debug port in a strange state which prevents node-debug from connecting to that port successfully.

When using 'node' instead of 'Electron', VS Code attaches successfully.

Trace output in this case:

Debugging with legacy protocol because Node version could not be determined.
62843: _attach: address: 127.0.0.1 port: 6009
62843: _attach: connected
62843: _initialize: got process id 62839 from node
62843: _injectDebuggerExtensions: frame based code injection failed with error 'No frames'
62843: _injectDebuggerExtensions: global code injection successful
62843: _startInitialize: stopped: false
62843: _startInitialize: no entry event after 10 retries; giving up
62843: _startInitialize2: fire initialized event
62843: _startInitialize2: in attach mode we guess stopOnEntry flag to be 'false''
62843: _startInitialize2: remember to do a 'Continue' later
62843: setFunctionBreakPointsRequest: result []
62843: setExceptionBreakPointsRequest: ["uncaught"]
62843: configurationDoneRequest: do a 'Continue'

Activity

  1. added
    debug
    bug
    on Feb 9, 2017
  2. roblourens commented on Feb 9, 2017

    @roblourens
    Member

    This is interesting, I can repro it just by using a web browser too.

    • "protocol": "legacy"
    • Start electron
    • Navigate to http://localhost:6009
    • It responds with the following:
    Type: connect
    V8-Version: 5.3.332.47
    Protocol-Version: 1
    Embedding-Host: Electron
    Content-Length: 0
    
    • Start the debug session - see the same thing as when using 'auto'

    So Electron is listening to http requests on that port too.

  3. roblourens commented on Feb 9, 2017

    @roblourens
    Member

    Oh, it just thinks the request is from a debugger. Then it probably thinks it's already attached and doesn't want to talk to a second debugger.

  4. roblourens commented on Feb 9, 2017

    @roblourens
    Member

    I see that message is still sent again when the debugger connects. It just closes the socket after sending that message. And looking at the code - https://github.com/electron/electron/blob/22b21d04bdbb43be52a90a3b05fdbd9b4278feea/atom/browser/node_debugger.cc#L148 - it looks like it wouldn't send the message again if it thought it was already attached to a debugger. I don't see anything here that explains why it's closing the socket.

  5. roblourens commented on Feb 15, 2017

    @roblourens
    Member

    I can't figure it out. I'd have to build Chromium to investigate deeper. A couple options:

    • Flip it around and test for the legacy protocol first by opening a socket to the address/port. We should be able to disconnect cleanly before attaching for real from the debug adapter. And I've tested that it doesn't screw up an inspector protocol instance. The socket gets this message:
    "HTTP/1.0 400 Bad Request
    Content-Type: text/html; charset=UTF-8
    
    WebSockets request was expected
    

    and is closed. And I can then attach with node2.

    Do you think this is safe?

    • Or, we'll have to not do version probing for attach. In this case, I would actually consider looking at port numbers and assuming that 5858 is legacy, and 9229 is inspector, as you proposed before.
  6. roblourens commented on Feb 16, 2017

    @roblourens
    Member

    My PR implements the first option. It actually doesn't work for Electron right now - it gives the same problem as above when the debug adapter attaches. But I can't figure out why, because it's doing exactly the same thing to disconnect as the debug adapter, which has no problem connecting and disconnecting to electron multiple times. I must be missing a step.

  7. weinand commented on Feb 16, 2017

    @weinand
    ContributorAuthor

    roblourens since the PR doesn't help with Electron, I suggest that we do not "rush" this and investigate more in the next milestone.

  8. added this to the March 2017 milestone on Mar 6, 2017
  9. roblourens commented on Mar 27, 2017

    @roblourens
    Member
  10. michelkaporin commented on Mar 31, 2017

    @michelkaporin
    Contributor

    Trying to verify it, steps described by Andre Weinand (@weinand) still result in "Debugging with legacy protocol because Node version could not be determined" message without no subsequent debugger attaching. In fact, it does not attach simply in auto setting for protocol at all.

  11. weinand commented on Mar 31, 2017

    @weinand
    ContributorAuthor

    Not critical since our Electron launch configuration snippet sets the protocol to 'legacy' explicitly.

  12. roblourens commented on Apr 4, 2017

    @roblourens
    Member

    I did find a mistake in my code, but even fixing that, I get the same result. Really weird. But it does work with Electron 1.5-1.6 regardless at least. I'll debug some more since this is definitely possible.

  13. roblourens commented on Sep 12, 2018

    @roblourens
    Member

    Not concerned about this anymore

  14. added
    *out-of-scope
    on Sep 12, 2018
  15. removed this from the On Deck milestone on Sep 12, 2018
  16. vscodebot commented on Sep 12, 2018

    @vscodebot

    This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

    If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

    Thanks for your understanding and happy coding!

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

Metadata

Metadata

Labels

*out-of-scopebugdebugverification-found

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions