|
@@ -21,7 +21,6 @@ const INITIAL_DELAY_MS = parseIntFromSplitTest(
|
|
|
'user-content-domain-access-check-delay',
|
|
'user-content-domain-access-check-delay',
|
|
|
30_000
|
|
30_000
|
|
|
)
|
|
)
|
|
|
-const DELAY_BETWEEN_PROBES_MS = 1_000
|
|
|
|
|
const TIMEOUT_MS = 30_000
|
|
const TIMEOUT_MS = 30_000
|
|
|
const FULL_SIZE = 739
|
|
const FULL_SIZE = 739
|
|
|
const FULL_HASH =
|
|
const FULL_HASH =
|
|
@@ -43,9 +42,6 @@ const CHUNKS = [
|
|
|
hash: '8278914487a3a099c9af5aa22ed836d6587ca0beb7bf9a059fb0409667b3eb3d',
|
|
hash: '8278914487a3a099c9af5aa22ed836d6587ca0beb7bf9a059fb0409667b3eb3d',
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
-async function sleep(ms: number) {
|
|
|
|
|
- return new Promise(resolve => setTimeout(resolve, ms))
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
function pickZone() {
|
|
function pickZone() {
|
|
|
const x = Math.random()
|
|
const x = Math.random()
|
|
@@ -198,30 +194,36 @@ export async function checkUserContentDomainAccess() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let failed = 0
|
|
let failed = 0
|
|
|
|
|
+ let ignoreResult = false
|
|
|
const epochBeforeCheck = networkEpoch
|
|
const epochBeforeCheck = networkEpoch
|
|
|
- for (const { url, init, estimatedSize, hash, chunks } of cases) {
|
|
|
|
|
- await sleep(DELAY_BETWEEN_PROBES_MS)
|
|
|
|
|
|
|
+ await Promise.all(
|
|
|
|
|
+ cases.map(async ({ url, init, estimatedSize, hash, chunks }) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await singleCheck(url, init, estimatedSize, hash, chunks)
|
|
|
|
|
+ } catch (err: any) {
|
|
|
|
|
+ if (!navigator.onLine || epochBeforeCheck !== networkEpoch) {
|
|
|
|
|
+ // It is very likely that the request failed because we are offline or
|
|
|
|
|
+ // the network connection changed just now.
|
|
|
|
|
+ ignoreResult = true
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ignoreResult) return
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- await singleCheck(url, init, estimatedSize, hash, chunks)
|
|
|
|
|
- } catch (err: any) {
|
|
|
|
|
- if (!navigator.onLine || epochBeforeCheck !== networkEpoch) {
|
|
|
|
|
- // It is very likely that the request failed because we are offline or
|
|
|
|
|
- // the network connection changed just now.
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
- failed++
|
|
|
|
|
- OError.tag(err, 'user-content-domain-access-check failed', {
|
|
|
|
|
- url,
|
|
|
|
|
- init,
|
|
|
|
|
- })
|
|
|
|
|
- if (isSplitTestEnabled('report-user-content-domain-access-check-error')) {
|
|
|
|
|
- captureException(err)
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error(OError.getFullStack(err), OError.getFullInfo(err))
|
|
|
|
|
|
|
+ failed++
|
|
|
|
|
+ OError.tag(err, 'user-content-domain-access-check failed', {
|
|
|
|
|
+ url,
|
|
|
|
|
+ init,
|
|
|
|
|
+ })
|
|
|
|
|
+ if (
|
|
|
|
|
+ isSplitTestEnabled('report-user-content-domain-access-check-error')
|
|
|
|
|
+ ) {
|
|
|
|
|
+ captureException(err)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.error(OError.getFullStack(err), OError.getFullInfo(err))
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
+ if (ignoreResult) return false
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
await postJSON('/record-user-content-domain-access-check-result', {
|
|
await postJSON('/record-user-content-domain-access-check-result', {
|