edge-runtime: InvalidWorkerCreation: worker boot error: failed to create the graph

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When I serve a function locally that imports a file outside /supabase/functions I get the error:

{"code":"BOOT_ERROR","message":"Worker failed to boot (please check logs)"}

The error does not occur when launching the function with $ deno run.

Logs

serving the request with ***/supabase/functions/hello-world
failed to create the graph
An error has occured
InvalidWorkerCreation: worker boot error: failed to create the graph
    at async UserWorker.create (ext:sb_user_workers/user_workers.js:145:15)
    at async Object.handler (file:///root/index.ts:154:22)
    at async respond (ext:sb_core_main_js/js/http.js:163:14) {
  name: "InvalidWorkerCreation"
}

Reproduce steps

  1. $ supabase functions new hello-world
  2. Replace hello-world/index.ts with:
    // @deno-types="npm:@types/express@4.17.15"
    import express, { Request, Response } from 'npm:express@4.21.0';
    import { hello } from '../../../lib.ts';
    
    const app = express();
    app.use(express.json());
    
    const port = 3000;
    
    app.get('/hello-world', (_: Request, res: Response) => {
      res.send(hello());
    });
    
    app.listen(port, () => {});
    
  3. create a file lib.ts in the project root containing the following:
    export function hello() : string {
      return 'Hello World!';
    }
    
  4. run the function with supabase: $ supabase functions serve hello-world --no-verify-jwt the error occurs
  5. run the function with deno (from within the /supabase/functions/hello-world folder): $ deno run -A index.ts no issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (5 by maintainers)

Most upvoted comments

This issue seems to be caused by the CLI only mounting the /supabase/functions directory that exists on the host machine into the edge runtime container. From the container’s perspective, it looks like no files exist in the parent directory, and as a result, lib.ts fails to load.

// docker inspect <edge runtime container id>
...
"Mounts": [
    {
        "Type": "volume",
        "Name": "supabase_edge_runtime_cli",
        "Source": "/var/lib/docker/volumes/supabase_edge_runtime_cli/_data",
        "Destination": "/root/.cache/deno",
        "Driver": "local",
        "Mode": "rw",
        "RW": true,
        "Propagation": ""
    },
    {
        "Type": "bind",
        "Source": "/Users/nyan/Documents/repository/cli/supabase/functions",
        "Destination": "/Users/nyan/Documents/repository/cli/supabase/functions",
        "Mode": "ro",
        "RW": false,
        "Propagation": "rprivate"
    }
],
...
serving the request with ***/supabase/functions/hello-world
failed to create the graph
An error has occured

And simply exposing a failed to create the graph message seems problematic. We actually have a source about why the graph failed to be created for some reason, but we didn’t render it to the console or in the response.

Regarding the mount issue you’re having, there’s nothing the edge runtime can do to fix it, but the error message needs improvement, so I’ll be submitting a PR soon.

–

Error message should be able to be improved as follows:

Response

{
    "msg": "InvalidWorkerCreation: worker boot error: failed to create the graph: Module not found \"file:///workspaces/lib.ts\".\n    at file:///workspaces/edge-runtime/examples/serve/index.ts:3:23"
}

Console

worker boot error: failed to create the graph: Module not found "file:///workspaces/lib.ts".
    at file:///workspaces/edge-runtime/examples/serve/index.ts:3:23    
InvalidWorkerCreation: worker boot error: failed to create the graph: Module not found "file:///workspaces/lib.ts".
    at file:///workspaces/edge-runtime/examples/serve/index.ts:3:23
    at async UserWorker.create (ext:sb_user_workers/user_workers.js:145:15)
    at async createWorker (file:///workspaces/edge-runtime/examples/main/index.ts:85:12)
    at async callWorker (file:///workspaces/edge-runtime/examples/main/index.ts:103:22)
    at async respond (ext:sb_core_main_js/js/http.js:163:14) {
  name: "InvalidWorkerCreation"
}

Well…it’s complicated, but it’s possible…if you’re good with Docker.

Finding the file in issue is possible with strace. You can access the shell of a container running edge runtime via docker exec -it <edge runtime container id> /bin/bash.

From there, you need to install the necessary packages for tracing by typing apt-get update && apt-get install -y htop strace.

You should be able to find the pid of the edge runtime using htop, which will allow you to observe the syscalls that the edge runtime is calling in real-time via strace.

스크린샷 2024-09-25 오전 10 06 28

After you type strace, as shown below, the shell will log syscalls until you press Ctrl+C. 스크린샷 2024-09-25 오전 10 07 54

Now send a request and observe the logs that are written to the shell. If you’ve followed these instructions well, you should have a syscall logged in your shell that failed to open the file, like this.

스크린샷 2024-09-25 오전 10 12 38

I hope you find these instructions helpful. Have a great day!

Yeah in such a case like yours, the syscall log would look normal, so the method I suggested instructions above would not have been able to resolve the issue.

There are many other cases where a graph error is emitted besides the file not being found, so I will submit a patch in the near future to expose the detailed error.

Yeah, it should because supabase/functions is the mount point of its container. All subpaths for this path should be recognizable from edge runtime.