From b4c03e63ae342865fd3c228b1a6c8f245a4b05c3 Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Date: Fri, 18 Oct 2024 06:24:17 +0800 Subject: [PATCH] fix: set autoselectfamily to fix undici ipv6 issues --- package.json | 1 + pnpm-lock.yaml | 9 +++++++++ server/index.ts | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/package.json b/package.json index 9ce9330f..9a2188a1 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "swagger-ui-express": "4.6.2", "swr": "2.2.5", "typeorm": "0.3.12", + "undici": "^6.20.1", "web-push": "3.5.0", "winston": "3.8.2", "winston-daily-rotate-file": "4.7.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7391a775..3a3f2451 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,6 +194,9 @@ importers: typeorm: specifier: 0.3.12 version: 0.3.12(sqlite3@5.1.4(encoding@0.1.13))(ts-node@10.9.1(@swc/core@1.6.5(@swc/helpers@0.5.11))(@types/node@20.14.8)(typescript@4.9.5)) + undici: + specifier: ^6.20.1 + version: 6.20.1 web-push: specifier: 3.5.0 version: 3.5.0 @@ -8768,6 +8771,10 @@ packages: undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + undici@6.20.1: + resolution: {integrity: sha512-AjQF1QsmqfJys+LXfGTNum+qw4S88CojRInG/6t31W/1fk6G59s92bnAvGz5Cmur+kQv2SURXEvvudLmbrE8QA==} + engines: {node: '>=18.17'} + unicode-canonical-property-names-ecmascript@2.0.0: resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==} engines: {node: '>=4'} @@ -19486,6 +19493,8 @@ snapshots: undici-types@5.26.5: {} + undici@6.20.1: {} + unicode-canonical-property-names-ecmascript@2.0.0: {} unicode-emoji-utils@1.2.0: diff --git a/server/index.ts b/server/index.ts index 96590361..23f9ee94 100644 --- a/server/index.ts +++ b/server/index.ts @@ -37,8 +37,15 @@ import dns from 'node:dns'; import net from 'node:net'; import path from 'path'; import swaggerUi from 'swagger-ui-express'; +import { Agent, setGlobalDispatcher } from 'undici'; import YAML from 'yamljs'; +// Set the global dispatcher to use autoSelectFamily +// attempt to fix ipv6 issues +setGlobalDispatcher( + new Agent({ connect: { timeout: 60_000, autoSelectFamily: true } }) +); + if (process.env.forceIpv4First === 'true') { dns.setDefaultResultOrder('ipv4first'); net.setDefaultAutoSelectFamily(false);