Resolve the Seafile host over IPv4 only (musl/Alpine ENOTFOUND on IPv6 NXDOMAIN); v2.17.3
Publish Container / build (push) Successful in 14m53s
Publish Container / build (push) Successful in 14m53s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
22c0038ebb
commit
1bf11a3669
4 files changed
+36
-3
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import dns from 'node:dns'
|
||||
import { SEAFILE_URL } from './config.js'
|
||||
|
||||
// Alpine's resolver (musl) fails the whole lookup when a DNS server answers the IPv6 (AAAA)
|
||||
// query with "no such name" even though the IPv4 answer is fine, so Node reports ENOTFOUND for
|
||||
// a host that resolves. Ask for IPv4 only, and only for the Seafile host.
|
||||
export function preferIpv4ForSeafile() {
|
||||
let host = ''
|
||||
try {
|
||||
host = SEAFILE_URL ? new URL(SEAFILE_URL).hostname : ''
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!host) return
|
||||
|
||||
const originalLookup = dns.lookup
|
||||
dns.lookup = function lookup(hostname, options, callback) {
|
||||
if (hostname === host) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
options = {}
|
||||
} else if (typeof options === 'number') {
|
||||
options = { family: options }
|
||||
}
|
||||
if (!options?.family) options = { ...options, family: 4 }
|
||||
}
|
||||
return originalLookup.call(this, hostname, options, callback)
|
||||
}
|
||||
console.log(`[seafile-dns] resolving ${host} over IPv4 only`)
|
||||
}
|
||||
Reference in new issue
Block a user