Help debugging command that doesn't exit.

Is there a way to have Deno tell me what async tasks are still pending when a program ends? I'm using a third-party API, and AFAICT awaiting all the promises I can, but I still get to the end of my main() and deno doesn't exit. So I've got:
async function main() {
// [snip]
console.log("Done")
showPending()
}

function showPending() {
let {ops} = Deno.metrics()
for (let [key, value] of Object.entries(ops)) {
if (value.opsDispatched != value.opsCompleted) {
console.log(key, value)
}
}
console.log(Deno.resources())
}
async function main() {
// [snip]
console.log("Done")
showPending()
}

function showPending() {
let {ops} = Deno.metrics()
for (let [key, value] of Object.entries(ops)) {
if (value.opsDispatched != value.opsCompleted) {
console.log(key, value)
}
}
console.log(Deno.resources())
}
Which gives me:
[snip]
Done
op_read {
opsDispatched: 14,
opsDispatchedSync: 0,
opsDispatchedAsync: 14,
opsDispatchedAsyncUnref: 0,
opsCompleted: 13,
opsCompletedSync: 0,
opsCompletedAsync: 13,
opsCompletedAsyncUnref: 0,
bytesSentControl: 0,
bytesSentData: 0,
bytesReceived: 0
}
{
"0": "stdin",
"1": "stdout",
"2": "stderr",
"8": "childStdin",
"9": "childStdout",
"10": "child"
}
[snip]
Done
op_read {
opsDispatched: 14,
opsDispatchedSync: 0,
opsDispatchedAsync: 14,
opsDispatchedAsyncUnref: 0,
opsCompleted: 13,
opsCompletedSync: 0,
opsCompletedAsync: 13,
opsCompletedAsyncUnref: 0,
bytesSentControl: 0,
bytesSentData: 0,
bytesReceived: 0
}
{
"0": "stdin",
"1": "stdout",
"2": "stderr",
"8": "childStdin",
"9": "childStdout",
"10": "child"
}
Any suggestions? I guess I'll fire up a debugger...
C
CodyC396d ago
Well, since deno test --trace-ops does what I want, I just wrapped my call in a test and ran it that way. Looks like esbuild isn't cleaning up after itself:
- 1 async operation to op_read was started in this test, but never completed. The operation was started here:
at handleOpCallTracing (ext:core/01_core.js:216:42)
at opAsync (ext:core/01_core.js:209:15)
at read (ext:deno_io/12_io.js:108:28)
at FsFile.read (ext:deno_fs/30_fs.js:609:12)
at readMoreStdout (https://deno.land/x/esbuild@v0.17.12/mod.js:1894:49)
at https://deno.land/x/esbuild@v0.17.12/mod.js:1899:11
- 1 async operation to op_read was started in this test, but never completed. The operation was started here:
at handleOpCallTracing (ext:core/01_core.js:216:42)
at opAsync (ext:core/01_core.js:209:15)
at read (ext:deno_io/12_io.js:108:28)
at FsFile.read (ext:deno_fs/30_fs.js:609:12)
at readMoreStdout (https://deno.land/x/esbuild@v0.17.12/mod.js:1894:49)
at https://deno.land/x/esbuild@v0.17.12/mod.js:1899:11
C
CodyC396d ago
There's an undocumented stop() method that you have to call to avoid this problem. 🤦 https://deno.land/x/esbuild@v0.17.12/mod.js?s=stop This doesn't seem to be documented in the official API docs: https://esbuild.github.io/api/