@samitouri / QOSami-HFS / commits / 429a6f45

fix: self_check will now give priority to successful results

Massimo Melina committed Jun 7, 2026 at 17:20 UTC 429a6f452ec73ae936f0f495f1a92d1b7dc25dde
1 file changed +5 -2
src/selfCheck.ts
+5 -2
@@ -3,7 +3,7 @@ import { Middleware } from 'koa'
3 import { getProjectInfo } from './github'
4 import { isIP, isIPv6 } from 'net'
5 import _ from 'lodash'
6 -import { haveTimeout } from './cross'
6 +import { findDefined, haveTimeout } from './cross'
7 import { httpString } from './util-http'
8
9 let selfChecking = false
@@ -40,7 +40,7 @@ export async function selfCheck(url: string) {
40 selfChecking = true
41 for (const services of _.chunk(_.shuffle<PortScannerService>(prjInfo.selfCheckServices), 2)) {
42 try {
43 - return await Promise.any(services.map(async svc => {
43 + const results = await Promise.allSettled(services.map(async svc => {
44 if (!svc.url || svc.type) throw 'unsupported ' + svc.type // only default type supported for now
45 let { url: serviceUrl, body, regexpSuccess, regexpFailure, ...rest } = svc
46 const service = new URL(serviceUrl).hostname
@@ -56,6 +56,9 @@ export async function selfCheck(url: string) {
56 console.debug(service, 'responded', success)
57 return { success, service, url }
58 }))
59 + // prefer a positive check so a fast false negative doesn't mask a working service
60 + return findDefined(results, x => x.status === 'fulfilled' && x.value.success ? x.value : undefined)
61 + || findDefined(results, x => x.status === 'fulfilled' ? x.value : undefined)
62 }
63 catch (e: any) {
64 console.debug(e?.errors?.map(String) || e?.cause || String(e))