From 7289284118d30cc5d3f745ac1bcb695ab5a6a100 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 22:29:30 +0800 Subject: [PATCH] fix: Gamedig unable to resolve SRV records by removing redundant DNS resolution in GameDigMonitorType (#6923) Co-authored-by: louislam <1336778+louislam@users.noreply.github.com> --- server/monitor-types/gamedig.js | 24 +----------------- test/backend-test/monitors/test-gamedig.js | 29 ++++++---------------- 2 files changed, 8 insertions(+), 45 deletions(-) diff --git a/server/monitor-types/gamedig.js b/server/monitor-types/gamedig.js index 35a015f9..5d47f7d9 100644 --- a/server/monitor-types/gamedig.js +++ b/server/monitor-types/gamedig.js @@ -1,8 +1,6 @@ const { MonitorType } = require("./monitor-type"); const { UP } = require("../../src/util"); const { GameDig } = require("gamedig"); -const dns = require("dns").promises; -const net = require("net"); class GameDigMonitorType extends MonitorType { name = "gamedig"; @@ -11,15 +9,10 @@ class GameDigMonitorType extends MonitorType { * @inheritdoc */ async check(monitor, heartbeat, server) { - let host = monitor.hostname; - if (net.isIP(host) === 0) { - host = await this.resolveHostname(host); - } - try { const state = await GameDig.query({ type: monitor.game, - host: host, + host: monitor.hostname, port: monitor.port, givenPortOnly: Boolean(monitor.gamedigGivenPortOnly), }); @@ -31,21 +24,6 @@ class GameDigMonitorType extends MonitorType { throw new Error(e.message); } } - - /** - * Resolves a domain name to its IPv4 address. - * @param {string} hostname - The domain name to resolve (e.g., "example.dyndns.org"). - * @returns {Promise} - The resolved IP address. - * @throws Will throw an error if the DNS resolution fails. - */ - async resolveHostname(hostname) { - try { - const result = await dns.lookup(hostname); - return result.address; - } catch (err) { - throw new Error(`DNS resolution failed for ${hostname}: ${err.message}`); - } - } } module.exports = { diff --git a/test/backend-test/monitors/test-gamedig.js b/test/backend-test/monitors/test-gamedig.js index 63961062..79a22885 100644 --- a/test/backend-test/monitors/test-gamedig.js +++ b/test/backend-test/monitors/test-gamedig.js @@ -2,7 +2,6 @@ const { describe, test, mock } = require("node:test"); const assert = require("node:assert"); const { GameDigMonitorType } = require("../../../server/monitor-types/gamedig"); const { UP, PENDING } = require("../../../src/util"); -const net = require("net"); const { GameDig } = require("gamedig"); describe("GameDig Monitor", () => { @@ -40,11 +39,13 @@ describe("GameDig Monitor", () => { } }); - test("check() resolves hostname to IP address when hostname is not an IP", async () => { + test("check() passes hostname directly to GameDig when hostname is not an IP", async () => { const gamedigMonitor = new GameDigMonitorType(); + let capturedOptions = null; + mock.method(GameDig, "query", async (options) => { - assert.ok(net.isIP(options.host) !== 0, `Expected IP address, got ${options.host}`); + capturedOptions = options; return { name: "Test Server", ping: 50, @@ -66,6 +67,7 @@ describe("GameDig Monitor", () => { try { await gamedigMonitor.check(monitor, heartbeat, {}); + assert.strictEqual(capturedOptions.host, "localhost"); assert.strictEqual(heartbeat.status, UP); assert.strictEqual(heartbeat.msg, "Test Server"); assert.strictEqual(heartbeat.ping, 50); @@ -74,7 +76,7 @@ describe("GameDig Monitor", () => { } }); - test("check() uses IP address directly without DNS resolution when hostname is IPv4", async () => { + test("check() passes IPv4 address directly to GameDig", async () => { const gamedigMonitor = new GameDigMonitorType(); let capturedOptions = null; @@ -109,7 +111,7 @@ describe("GameDig Monitor", () => { } }); - test("check() uses IP address directly without DNS resolution when hostname is IPv6", async () => { + test("check() passes IPv6 address directly to GameDig", async () => { const gamedigMonitor = new GameDigMonitorType(); let capturedOptions = null; @@ -233,21 +235,4 @@ describe("GameDig Monitor", () => { await assert.rejects(gamedigMonitor.check(monitor, heartbeat, {}), /Error/); }); - - test("resolveHostname() returns IP address when given valid hostname", async () => { - const gamedigMonitor = new GameDigMonitorType(); - - const resolvedIP = await gamedigMonitor.resolveHostname("localhost"); - - assert.ok(net.isIP(resolvedIP) !== 0, `Expected valid IP address, got ${resolvedIP}`); - }); - - test("resolveHostname() rejects when DNS resolution fails for invalid hostname", async () => { - const gamedigMonitor = new GameDigMonitorType(); - - await assert.rejects( - gamedigMonitor.resolveHostname("this-domain-definitely-does-not-exist-12345.invalid"), - /DNS resolution failed/ - ); - }); });