mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #16775 from overleaf/bg-clsi-timeout-use-fetchutils-connect-timeout
Update UrlFetcher to use custom agent with connect timeout GitOrigin-RevId: c92dc27a0e682b0b79859b3521bf64cbf8485345
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
const fs = require('fs')
|
||||
const logger = require('@overleaf/logger')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { fetchStream } = require('@overleaf/fetch-utils')
|
||||
const {
|
||||
CustomHttpAgent,
|
||||
CustomHttpsAgent,
|
||||
fetchStream,
|
||||
} = require('@overleaf/fetch-utils')
|
||||
const { URL } = require('url')
|
||||
const { pipeline } = require('stream/promises')
|
||||
const Metrics = require('./Metrics')
|
||||
|
||||
const MAX_CONNECT_TIME = 1000
|
||||
const httpAgent = new CustomHttpAgent({ connectTimeout: MAX_CONNECT_TIME })
|
||||
const httpsAgent = new CustomHttpsAgent({ connectTimeout: MAX_CONNECT_TIME })
|
||||
|
||||
async function pipeUrlToFileWithRetry(url, filePath) {
|
||||
let remainingAttempts = 3
|
||||
let lastErr
|
||||
@@ -40,6 +48,10 @@ async function pipeUrlToFile(url, filePath) {
|
||||
|
||||
const stream = await fetchStream(url, {
|
||||
signal: AbortSignal.timeout(60 * 1000),
|
||||
// provide a function to get the agent for each request
|
||||
// as there may be multiple requests with different protocols
|
||||
// due to redirects.
|
||||
agent: _url => (_url.protocol === 'https:' ? httpsAgent : httpAgent),
|
||||
})
|
||||
|
||||
const atomicWrite = filePath + '~'
|
||||
|
||||
Reference in New Issue
Block a user