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

Leaky timeout in Deno with wasm.js and esbuild.build #3552

Closed
hansottowirtz opened this issue Dec 17, 2023 · 2 comments
Closed

Leaky timeout in Deno with wasm.js and esbuild.build #3552

hansottowirtz opened this issue Dec 17, 2023 · 2 comments

Comments

@hansottowirtz
Copy link

hansottowirtz commented Dec 17, 2023

Running deno test --allow-all --trace-ops index.ts on this file results in the following error:

running 1 test from ./index.ts
esbuild ... FAILED (208ms)

 ERRORS 

esbuild => ./index.ts:41:6
error: Leaking async ops:
  - 1 async operation to sleep for a duration was started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call. The operation was started here:
    at handleOpCallTracing (ext:core/01_core.js:561:42)
    at op_sleep (ext:core/01_core.js:378:21)
    at runAfterTimeout (ext:deno_web/02_timers.js:229:20)
    at initializeTimer (ext:deno_web/02_timers.js:187:3)
    at setTimeout (ext:deno_web/02_timers.js:331:10)
    at runtime.scheduleTimeoutEvent (https://deno.land/x/[email protected]/wasm.js:1794:3686)
    at <anonymous> (https://deno.land/x/[email protected]/esbuild.wasm:1:940909)
    at <anonymous> (https://deno.land/x/[email protected]/esbuild.wasm:1:110194)
    at <anonymous> (https://deno.land/x/[email protected]/esbuild.wasm:1:605886)
    at <anonymous> (https://deno.land/x/[email protected]/esbuild.wasm:1:619713)

 FAILURES 

esbuild => ./index.ts:41:6

FAILED | 0 passed | 1 failed (216ms)

error: Test failed

File:

import * as esbuild from "https://deno.land/x/[email protected]/wasm.js";

await esbuild.initialize({
  wasmURL: "https://deno.land/x/[email protected]/esbuild.wasm",
  worker: false,
});

async function bundle(script: string) {
  const esbuildResult = await esbuild.build({
    entryPoints: ['entrypoint.js'],
    sourcemap: 'external',
    target: 'es2022',
    format: 'esm',
    write: false,
    outdir: 'out',
    bundle: true,
    plugins: [
      {
        name: 'simple',
        setup(build) {
          build.onResolve({ filter: /^entrypoint\.js$/ }, () => {
            return {
              path: "/entrypoint.js",
              namespace: 'file',
            }
          })
          build.onLoad({ filter: /^\/entrypoint\.js$/ }, () => {
            return {
              contents: script,
              loader: 'js',
            }
          })
        }
      }
    ]
  });
  esbuild.stop();
  return esbuildResult.outputFiles[0].text;
}

Deno.test("esbuild", async () => {
  await bundle(`
    function add(a, b) {
      return a + b;
    }
    console.log(add(1, 2));
  `);
});

We're running this file in Deno Deploy, which is why we have to use the wasm version with worker: false.

@evanw
Copy link
Owner

evanw commented Dec 17, 2023

The Go runtime is doing this. You could try asking them about it here: https://github.com/golang/go. Although I’m guessing this is normal. The Go language is garbage collected and the garbage collector has its own timers and scheduling logic that is designed for long-running tasks. Another option could be to look into how to disable this false-positive warning in Deno. I don’t use Deno myself so I don’t know how to do that. Anyway this does not appear to be a problem with esbuild.

@evanw
Copy link
Owner

evanw commented Dec 18, 2023

Actually, I think I can hack esbuild's WASM runner to clear these timeouts from Go. I'll give that a try.

@evanw evanw closed this as completed in f38cbe6 Dec 18, 2023
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

3 participants
@evanw @hansottowirtz and others