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

NodeWorker.sendMessageToWorker fails with multi-byte code points in JSON #50516

Open
connor4312 opened this issue Nov 1, 2023 · 5 comments
Open
Labels
inspector Issues and PRs related to the V8 inspector protocol worker Issues and PRs related to Worker support.

Comments

@connor4312
Copy link
Contributor

connor4312 commented Nov 1, 2023

Version

21.1.0

Platform

Darwin mbp.peet.io 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:27 PDT 2023; root:xnu-10002.41.9~6/RELEASE_X86_64 x86_64

Subsystem

inspector

What steps will reproduce the bug?

From a user's point of view...

  1. Debug a script like this in VS Code
const { Worker, isMainThread } = require('worker_threads');

if (isMainThread) {
  new Worker(__filename);
} else {
  debugger;
}
  1. Ensure the worker_thread session is select and run console.log('本機磁碟')
  2. Nothing happens (an error behind the scenes)

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

It should log 本機磁碟

What do you see instead?

An error

Additional information

Behind the scenes, this calls

{
  "id": 1027,
  "method": "NodeWorker.sendMessageToWorker",
  "params": {
    "message": "{\"id\":1014,\"method\":\"Debugger.evaluateOnCallFrame\",\"params\":{\"expression\":\"console.log('本機磁碟')\\n//# sourceURL=eval-1e14c9c5.repl\\n\",\"includeCommandLineAPI\":true,\"objectGroup\":\"console\",\"generatePreview\":true,\"callFrameId\":\"-7882104772351236078.1.0\"}}",
    "sessionId": "1"
  }
}

This is created by simply JSON.stringify'ing the relevant CDP call.

However, this results in

{
  "method": "NodeWorker.receivedMessageFromWorker",
  "params": {
    "sessionId": "1",
    "message": "{\"error\":{\"code\":-32700,\"message\":\"Message must be a valid JSON\"}}"
  }
}

Which seems to come from here

reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
. I would expect any JSON created by JSON.stringify would be able to be parsed by the NodeWorker domain.

This causes more 'real' issues when users have paths with multi-byte codepoints, as reported in microsoft/vscode-js-debug#1798 and microsoft/vscode-js-debug#2043

@debadree25
Copy link
Member

Is there script to reproduce this without having to using the vscode debugger

@debadree25 debadree25 added the inspector Issues and PRs related to the V8 inspector protocol label Nov 8, 2023
@connor4312
Copy link
Contributor Author

connor4312 commented Nov 8, 2023

This should be pretty easily reproducible by manually interacting with the NodeWorker domain using require('inspector'). The parsing fails when the code point is in any message sent to the worker, no specific patterns or setup is necessary.

@cola119
Copy link
Member

cola119 commented Dec 24, 2023

Logging English characters works fine.
image

@cola119
Copy link
Member

cola119 commented Dec 30, 2023

This issue could be solved by updating our copies of files related to inspector protocol to the latest. I'm working on it.

@connor4312
Copy link
Contributor Author

This causes programs to break when they use module.register from a filename with multibyte code points (see most recently linked issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inspector Issues and PRs related to the V8 inspector protocol worker Issues and PRs related to Worker support.
Projects
None yet
Development

No branches or pull requests

3 participants