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

[Miniflare 3] Step debugging with multiple workers #735

Closed
frandiox opened this issue Nov 1, 2023 · 2 comments
Closed

[Miniflare 3] Step debugging with multiple workers #735

frandiox opened this issue Nov 1, 2023 · 2 comments

Comments

@frandiox
Copy link
Contributor

frandiox commented Nov 1, 2023

Hello! I'm having issues setting up step debugging when using multiple workers in Miniflare 3:

new Miniflare({
   ...,
   port: 3000,
   inspectorPort: 9229,
   host: 'localhost',
   workers: [
     {
       name: 'oxygen',
       modules: true,
       script: 'export default { fetch: (request, env) => env.hydrogen.fetch(request) }',
       serviceBindings: {
            hydrogen: 'hydrogen',
       }
     },
     {
       name: 'hydrogen',
       modulesRoot: path.dirname(userBundlePath),
       modules: [
          {
             type: 'ESModule',
             path: userBundlePath,
             contents: await fs.readFile(userBundlePath),
          },
       ]
     },
   ],
})

I'm attaching a debugger in VSCode with the following launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Test",
      "type": "node",
      "request": "attach",
      "port": 9229,
      "cwd": "/",
      "resolveSourceMapLocations": null,
      "attachExistingChildren": false,
      "autoAttachChildProcesses": false
    }
  ]
}

The user app is placed in the hydrogen worker, while the oxygen worker contains some logic for asset handling and other debugging features (not shown in this example).

The problem is that VSCode only tracks the code for the oxygen worker (I assume it's just because it comes first) and completely ignores the other workers.

If I remove oxygen and move hydrogen to the first position, then step debugging works.

Is there any way to make it work with multiple workers? Or should we just use 1 single worker in development? I can certainly move the custom logic in oxygen to a Node.js server proxy and call mf.dispatchFetch(...) instead.

Thanks!

@frandiox
Copy link
Contributor Author

frandiox commented Nov 1, 2023

Alright I think I figured it out. VSCode connects automatically to the first source returned by the /json request to the inspector port.
It's possible to choose directly the WebSocket address in launch.json:

-      "port": 9229,
+     "websocketAddress": "ws://127.0.0.1:9229/core:user:hydrogen",

Alternatively, I guess we could try to connect to a proxy port that only returns core:user:hydrogen in /json 🤔

@mrbbot Closing this but please let me know if you have any idea on how to make this simpler 🙌

@frandiox frandiox closed this as completed Nov 1, 2023
@mrbbot
Copy link
Contributor

mrbbot commented Nov 1, 2023

Was just about to reply with websocketAddress. I think that's the best solution here. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants