denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.96k stars 5.23k forks source link

npm:undici not working (Connect Timeout Error) #19532

Open KohnoseLami opened 1 year ago

KohnoseLami commented 1 year ago

It appears to have been resolved as a result of the following issue, but it still does not work in my environment. https://github.com/denoland/deno/issues/16710

PS D:\Desktop\Projects\Discord\Deno> node index.mjs
{
  data: {
    t: 'READY',
    s: 1,
    op: 0,
    d: {
      v: 10,
      user_settings: {},
      user: [Object],
      shard: [Array],
      session_type: 'normal',
      session_id: '329437320dbddd3c074ac6ca6815161e',
      resume_gateway_url: 'wss://gateway-us-east1-b.discord.gg',
      relationships: [],
      private_channels: [],
      presences: [],
      guilds: [Array],
      guild_join_requests: [],
      geo_ordered_rtc_regions: [Array],
      application: [Object],
      _trace: [Array]
    }
  },
  shardId: 0
}
PS D:\Desktop\Projects\Discord\Deno> deno run --allow-all index.ts
error: Uncaught (in promise) ConnectTimeoutError: Connect Timeout Error
    at onConnectTimeout (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/core/connect.js:182:24)
    at file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/core/connect.js:129:46
    at file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/core/connect.js:168:33
    at Object.action (ext:deno_web/02_timers.js:153:11)
    at handleTimerMacrotask (ext:deno_web/02_timers.js:67:10)
    at eventLoopTick (ext:core/01_core.js:189:21)

I used @discordjs/rest to test the behavior, but only undici actually causes errors.

import { request } from "npm:undici"
await request("https://jsonplaceholder.typicode.com/todos/1")

My enviroments: deno 1.34.3 (release, x86_64-pc-windows-msvc) v8 11.5.150.2 typescript 5.0.4

crowlKats commented 1 year ago

I am not able to reproduce this; possibly a windows specific error?

KohnoseLami commented 1 year ago

Maybe yes I prepared another Windows machine for the experiment and did it from installation, but I get a similar error. I ran it on Windows 11 and Windows 10 and it was similar.

PS C:\Users\Lami> irm https://deno.land/install.ps1 | iex
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 30.3M  100 30.3M    0     0  30.3M      0  0:00:01 --:--:--  0:00:01 30.3M
Deno was installed successfully to C:\Users\Lami\.deno\bin\deno.exe
Run 'deno --help' to get started
Stuck? Join our Discord https://discord.gg/deno
PS C:\Users\Lami> deno
Deno 1.35.0
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { request } from "npm:undici"
await request("https://jsonplaceholder.typicode.com/todos/1")
Uncaught ConnectTimeoutError: Connect Timeout Error
    at onConnectTimeout (file:///C:/Users/Lami/AppData/Local/deno/npm/registry.npmjs.org/undici/5.22.1/lib/core/connect.js:182:24)
    at file:///C:/Users/Lami/AppData/Local/deno/npm/registry.npmjs.org/undici/5.22.1/lib/core/connect.js:129:46
    at file:///C:/Users/Lami/AppData/Local/deno/npm/registry.npmjs.org/undici/5.22.1/lib/core/connect.js:168:33
    at Object.action (ext:deno_web/02_timers.js:153:11)
    at handleTimerMacrotask (ext:deno_web/02_timers.js:67:10)
    at eventLoopTick (ext:core/01_core.js:189:21)
>

Of course fetch works in environments where undici doesn't work. So it's not about the network or anything.

> await fetch('https://jsonplaceholder.typicode.com/todos/1')
Response {
  body: ReadableStream { locked: false },
  bodyUsed: false,
  headers: Headers {
  "access-control-allow-credentials": "true",
  age: "630",
  "alt-svc": 'h3=":443"; ma=86400',
  "cache-control": "max-age=43200",
  "cf-cache-status": "HIT",
  "cf-ray": "7e4d1b900aca2635-NRT",
  "content-type": "application/json; charset=utf-8",
  date: "Tue, 11 Jul 2023 01:00:07 GMT",
  etag: 'W/"53-hfEnumeNh6YirfjyjaujcOPPT+s"',
  expires: "-1",
  nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
  pragma: "no-cache",
  "report-to": '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=8JU1QfR3ezrPM5UYvJGo2DY43mIdswRNi'... 179 more characters,
  server: "cloudflare",
  vary: "Origin, Accept-Encoding",
  via: "1.1 vegur",
  "x-content-type-options": "nosniff",
  "x-powered-by": "Express",
  "x-ratelimit-limit": "1000",
  "x-ratelimit-remaining": "999",
  "x-ratelimit-reset": "1683994374"
},
  ok: true,
  redirected: false,
  status: 200,
  statusText: "OK",
  url: "https://jsonplaceholder.typicode.com/todos/1"
}
kravetsone commented 4 months ago

+1.

I try to use it in WSL and all works fine. But if I switch to Windows I get the same error...

It is lock to use my framework on Windows in Deno runtime...

https://gramio.netlify.app/ https://jsr.io/@gramio/core