D
Deno

help

error: BadResource: Bad resource ID

Vv1rtl3/26/2023
I'm writing tests for https://github.com/deno-libs/tinyhttp/pull/9.
import { describe, expect, it, run } from 'https://deno.land/x/tincan@1.0.1/mod.ts'
import { App } from '../../app.ts'

describe('Request properties', () => {
it.only('should have default HTTP Request properties', async () => {
const app = new App()
app.get('/', (req, res) => {
res.json({ url: req.url })
})
const listener = Deno.listen({ port: 8080, hostname: 'localhost' })

setTimeout(() => {
fetch(`http://localhost:8080`).then((res) => res.json()).then((json) => {
expect(json).toEqual({ url: `http://localhost:8080/` })
})
}, 0)

const conn = await listener.accept()
const requests = Deno.serveHttp(conn)
const { request, respondWith } = (await requests.nextRequest())!
const response = await app.handler(request, conn)
if (response) {
respondWith(response)
// Deno.close(conn.rid)

listener.close()
}
})
})
import { describe, expect, it, run } from 'https://deno.land/x/tincan@1.0.1/mod.ts'
import { App } from '../../app.ts'

describe('Request properties', () => {
it.only('should have default HTTP Request properties', async () => {
const app = new App()
app.get('/', (req, res) => {
res.json({ url: req.url })
})
const listener = Deno.listen({ port: 8080, hostname: 'localhost' })

setTimeout(() => {
fetch(`http://localhost:8080`).then((res) => res.json()).then((json) => {
expect(json).toEqual({ url: `http://localhost:8080/` })
})
}, 0)

const conn = await listener.accept()
const requests = Deno.serveHttp(conn)
const { request, respondWith } = (await requests.nextRequest())!
const response = await app.handler(request, conn)
if (response) {
respondWith(response)
// Deno.close(conn.rid)

listener.close()
}
})
})
When running this test I get either this:
Request properties > should have default HTTP Request properties => https://deno.land/x/tincan@1.0.1/src/runner.ts:166:10
error: BadResource: Bad resource ID
Deno.close(conn.rid)
^
at Object.close (ext:core/01_core.js:396:25)
at ItNode.fn (file:///home/v1rtl/Coding/deno-libs/tinyhttp/tests/core/request.test.ts:29:12)
at async wrappedFn (https://deno.land/x/tincan@1.0.1/src/runner.ts:141:9)
Request properties > should have default HTTP Request properties => https://deno.land/x/tincan@1.0.1/src/runner.ts:166:10
error: BadResource: Bad resource ID
Deno.close(conn.rid)
^
at Object.close (ext:core/01_core.js:396:25)
at ItNode.fn (file:///home/v1rtl/Coding/deno-libs/tinyhttp/tests/core/request.test.ts:29:12)
at async wrappedFn (https://deno.land/x/tincan@1.0.1/src/runner.ts:141:9)
or this, if I uncomment that line:
error: AssertionError: Test case is leaking 1 resource:
- An inbound HTTP connection (rid 8) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
at assert (ext:deno_web/00_infra.js:353:11)
at resourceSanitizer (ext:cli/40_testing.js:414:5)
at async Object.exitSanitizer [as fn] (ext:cli/40_testing.js:432:7)
error: AssertionError: Test case is leaking 1 resource:
- An inbound HTTP connection (rid 8) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
at assert (ext:deno_web/00_infra.js:353:11)
at resourceSanitizer (ext:cli/40_testing.js:414:5)
at async Object.exitSanitizer [as fn] (ext:cli/40_testing.js:432:7)
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects.
Vv1rtl3/26/2023
what I'm trying to do is to close the server once a request has been done
AAapoAlas3/26/2023
conn.close() would be the normal API to close the connection, I think.
Vv1rtl3/26/2023
conn.close emits the same error as Deno.close(conn.rid)
AAapoAlas3/26/2023
Hmm... Maybe await the respondWith ... Not sure though.
Vv1rtl3/26/2023
I fixed with Deno.close(conn.rid + 1)... weird but it works
AAapoAlas3/26/2023
That sounds absolutely dirty, unsafe and unsound 😄 Not to kick you down of course, just that calculating another rid from one is probably really easy to break semi-randomly.
Vv1rtl3/29/2023
well nothing else worked lol
AAapoAlas3/29/2023
Yeah.

Looking for more? Join the community!

Recommended Posts
Recent deployment not working?Hi there I have an api that was working just fine not sure what happen but new deployments are not wHow do you get the path to a file relative to the module which is referencing it?```ts const GET_PROGRAM_QUERY = Deno.readFileSync("./GetProgram.gql"); ``` GetProgram.gql is a fileInvestigating memory leak after adding new app dependencyHi, I added an OpenTelemetry metrics reporting loop to a Deno program and found that Deno began leakVScode deno lint blew up again after update.It seems every time there's an extension update VScode lint blows up and will stop recognizing top limport cache not workingI can't install cache of my http imports:Why isn't this error caught?Basic code example: ``` try { Deno.remove("fakefile"); } catch (err) { console.log("File doesn'tUsing dynamic import with npm compatibility gives intermittent error "__DENO_NODE_GLOBAL_THIS_167935This is pretty hard to google because the number at the end of the error changes everytime it happenGraphql codegendoes anyone have a solution to generate the sdk using graphq-request with Deno?Deno Third Party Modules Web HooksIs there a way to see the webhook payload URL a package you have published is listening for?Does Deno Deploy support location based analytics?The free version does not seem to support it. Does the paid version support it?IPC solution for a process manager👋 I'm at day 7 of working on Pup (https://github.com/hexagon/pup) - a universal process manager rSpecifying config remotely or jsx on installI'm struggling quite a lot here. I originally recommended using this command: ```bash deno install -Is it possible to know what version of a dynamically-imported module was just imported?Right now, you can run code like `import('npm:lodash')`, which will get the latest version of lodashWhy am I getting an "Uncaught DOM Exception" in the Deno CLI?To replicate: 1. `deno` in the command line to initialize a Deno REPL ``` // Get an array of random Better way to allow downloading of files besides serving entire fileI'm trying to allow users to download files that are in a private folder which cannot be accessed puShare state between islandsHi. How could I share state between island. E.g. shopping cart. I click on add product and in some oIslands not working with Cloudflare DNS proxyI have deployed Deno on a remote server with nginx-ingress-controller that offers self-signed certifUpdate sub-directory for module already added to deno.land/xThe title pretty much says it all, but the module in question is `hot_mod`, and the current subdir iShould we, or how should we, use Deno as a sandbox for untrusted code?I've been using Deno in this context because of some of the nice security model features. However, ideno_bindgen type error: deno-ts(2345)Anyone else getting this with `deno_bindgen`? > Argument of type 'bigint' is not assignable to param