Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix: add dns caching (#3736)

Meier Lukasfb6b5e88ff3a
diff --git a/apps/tasks/src/main.ts b/apps/tasks/src/main.ts
index 57cbd1d7b..f996a1399 100644
--- a/apps/tasks/src/main.ts
+++ b/apps/tasks/src/main.ts
@@ -1,5 +1,5 @@
// This import has to be the first import in the file so that the agent is overridden before any other modules are imported.
-import "./undici-log-agent-override";
+import "./overrides";
import type { FastifyTRPCPluginOptions } from "@trpc/server/adapters/fastify";
import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify";
diff --git a/apps/tasks/src/undici-log-agent-override.ts b/apps/tasks/src/overrides.ts
similarity index 100%
rename from apps/tasks/src/undici-log-agent-override.ts
rename to apps/tasks/src/overrides.ts
diff --git a/package.json b/package.json
index 81afb9ca5..2ced545d7 100644
--- a/package.json
+++ b/package.json
@@ -98,6 +98,9 @@
"@types/node-unifi": "patches/@types__node-unifi.patch",
"trpc-to-openapi": "patches/trpc-to-openapi.patch"
},
+ "patchedDependencies": {
+ "@types/node-unifi": "patches/@types__node-unifi.patch"
+ },
"allowUnusedPatches": true,
"ignoredBuiltDependencies": [
"@scarf/scarf",
diff --git a/packages/common/package.json b/packages/common/package.json
index 09001ab75..ccad4bc05 100644
--- a/packages/common/package.json
+++ b/packages/common/package.json
@@ -8,6 +8,7 @@
".": "./index.ts",
"./types": "./src/types.ts",
"./server": "./src/server.ts",
+ "./init-dns": "./src/dns.ts",
"./client": "./src/client.ts",
"./env": "./env.ts"
},
@@ -30,6 +31,7 @@
"@homarr/log": "workspace:^0.1.0",
"@paralleldrive/cuid2": "^2.2.2",
"dayjs": "^1.11.15",
+ "dns-caching": "^0.2.5",
"next": "15.5.2",
"react": "19.1.1",
"react-dom": "19.1.1",
diff --git a/packages/common/src/dns.ts b/packages/common/src/dns.ts
new file mode 100644
index 000000000..6e1e65c7c
--- /dev/null
+++ b/packages/common/src/dns.ts
@@ -0,0 +1,22 @@
+import { DnsCacheManager } from "dns-caching";
+
+import { logger } from "@homarr/log";
+
+// Add global type augmentation for homarr
+declare global {
+ var homarr: {
+ dnsCacheManager?: DnsCacheManager;
+ // add other properties if needed
+ };
+}
+
+// Initialize global.homarr if not present
+// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+global.homarr ??= {};
+global.homarr.dnsCacheManager ??= new DnsCacheManager({
+ cacheMaxEntries: 1000,
+ forceMinTtl: 5 * 60 * 1000, // 5 minutes
+ logger,
+});
+
+global.homarr.dnsCacheManager.initialize();
diff --git a/packages/common/src/fetch-agent.ts b/packages/common/src/fetch-agent.ts
index f09261848..b541f5301 100644
--- a/packages/common/src/fetch-agent.ts
+++ b/packages/common/src/fetch-agent.ts
@@ -3,6 +3,9 @@ import { Agent } from "undici";
import { logger } from "@homarr/log";
+// The below import statement initializes dns-caching
+import "./dns";
+
export class LoggingAgent extends Agent {
constructor(...props: ConstructorParameters<typeof Agent>) {
super(...props);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7b309076a..65cf2117c 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -28,9 +28,6 @@ patchedDependencies:
'@types/node-unifi':
hash: 5e6ae51e2a17a7f9729bfa30b0eb3d0842a5810ac6db47603ab4a6efa1ed84c5
path: patches/@types__node-unifi.patch
- trpc-to-openapi:
- hash: 2ca3c16af0fcca0c736697ad4fe553a14f794524fa9ce0d5c3e8ee4aea76090c
- path: patches/trpc-to-openapi.patch
importers:
@@ -654,7 +651,7 @@ importers:
version: 2.2.2
trpc-to-openapi:
specifier: ^3.0.1
- version: 3.0.1(patch_hash=2ca3c16af0fcca0c736697ad4fe553a14f794524fa9ce0d5c3e8ee4aea76090c)(@trpc/[email protected]([email protected]))([email protected]([email protected]))([email protected])
zod:
specifier: ^4.1.5
version: 4.1.5
@@ -867,6 +864,9 @@ importers:
dayjs:
specifier: ^1.11.15
version: 1.11.18
+ dns-caching:
+ specifier: ^0.2.5
+ version: 0.2.5
next:
specifier: 15.5.2
@@ -5864,6 +5864,9 @@ packages:
resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
engines: {node: '>=8'}
+ resolution: {integrity: sha512-1cnB6i/OG4zfYbRnDjWZDT+FGLvOBuJlFIxVZvHBiaa62SCfaGoP4Si50O14HyoHmx1gadeGWigYXdX5LQAFvg==}
+
resolution: {integrity: sha512-wIU1eHk3Op7dFgELRdmOYlPYS4gP8HhH1ZmZa13QZF59y0fblzFDFmKPhyc05phCy2hze9OEvNZAsoljrs+72w==}
engines: {node: '>= 6.0.0'}
@@ -7614,6 +7617,10 @@ packages:
resolution: {integrity: sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==}
engines: {node: 20 || >=22}
+ resolution: {integrity: sha512-QIXZUBJUx+2zHUdQujWejBkcD9+cs94tLn0+YL8UrCh+D5sCXZ4c7LaEH48pNwRY3MLDgqUFyhlCyjJPf1WP0A==}
+ engines: {node: 20 || >=22}
+
resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==}
@@ -10723,7 +10730,7 @@ snapshots:
'@csstools/css-color-parser': 3.0.7(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])
'@csstools/css-parser-algorithms': 3.0.4(@csstools/[email protected])
'@csstools/css-tokenizer': 3.0.3
- lru-cache: 11.0.2
+ lru-cache: 11.1.0
dependencies:
@@ -14628,6 +14635,10 @@ snapshots:
dependencies:
path-type: 4.0.0
+ dependencies:
+ lru-cache: 11.1.0
+
dependencies:
yaml: 2.5.1
@@ -16661,6 +16672,8 @@ snapshots:
+
dependencies:
yallist: 3.1.1
@@ -19365,7 +19378,7 @@ snapshots:
- [email protected](patch_hash=2ca3c16af0fcca0c736697ad4fe553a14f794524fa9ce0d5c3e8ee4aea76090c)(@trpc/[email protected]([email protected]))([email protected]([email protected]))([email protected]):
dependencies:
'@trpc/server': 11.5.0([email protected])
co-body: 6.2.0