electron-builder: Differential download must fail after 10 seconds
When useMultipleRangeRequest is true, differential download must fail after 10 seconds.
DifferentialDownloader.ts:
private async doDownloadFile(tasks: Array<Operation>, fdList: Array<OpenedFile>): Promise<any> {
...
await new Promise((resolve, reject) => {
let w: any
if (this.options.isUseMultipleRangeRequest) {
w = executeTasksUsingMultipleRangeRequests(this, tasks, firstStream, oldFileFd, reject)
w(0)
return
}
...
})
}
multipleRangeDownloader.ts:
export function executeTasksUsingMultipleRangeRequests(
differentialDownloader: DifferentialDownloader,
tasks: Array<Operation>,
out: Writable,
oldFileFd: number,
reject: (error: Error) => void
): (taskOffset: number) => void {
const w = (taskOffset: number): void => {
...
const nextOffset = taskOffset + 1000
doExecuteTasks(
differentialDownloader,
{
tasks,
start: taskOffset,
end: Math.min(tasks.length, nextOffset),
oldFileFd,
},
out,
() => w(nextOffset),
reject
)
}
return w
}
function doExecuteTasks(differentialDownloader: DifferentialDownloader, options: PartListDataTask, out: Writable, resolve: () => void, reject: (error: Error) => void): void {
...
const requestOptions = differentialDownloader.createRequestOptions()
requestOptions.headers!.Range = ranges.substring(0, ranges.length - 2)
const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
if (!checkIsRangesSupported(response, reject)) {
return
}
const contentType = safeGetHeader(response, "content-type")
const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType)
if (m == null) {
reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`))
return
}
const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve)
dicer.on("error", reject)
response.pipe(dicer)
response.on("end", () => {
setTimeout(() => {
request.abort()
reject(new Error("Response ends without calling any handlers"))
}, 10000) <-- The timer isn't canceled after data processing is completed.
})
})
differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)
request.end()
}
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 19
Okay, here’s how you can configure Nginx to support multiple HTTP Range requests:
Nginx supports single HTTP Range requests (e.g.,
Range: bytes=0-1023) by default. If you want Nginx to handle requests containing multiple ranges (e.g.,Range: bytes=0-499, 1000-1499) and respond with amultipart/byterangescontent type, you need to use themax_rangesdirective.Add the
max_rangesdirective to thehttp,server, orlocationblock where you want to enable this feature. Set its value to the maximum number of ranges you want to allow. Setting it to0disablesmultipart/byterangesresponses entirely.Here’s an example configuration within a
locationblock, allowing up to 1000 ranges:Explanation:
max_ranges 10;: This line tells Nginx to process up to 10 byte ranges specified in theRangerequest header. If a request contains more than 10 ranges, Nginx might ignore theRangeheader or return an error.max_rangesin thehttpblock (global effect),serverblock (affects the entire virtual host), orlocationblock (affects requests matching the location). Placing it in the specificlocationblock serving large files is common.rootoralias). For requests handled viaproxy_pass, range processing is typically the responsibility of the backend server unless Nginx is configured with caching and has the full file cached.After modifying the configuration, remember to reload or restart the Nginx service for the changes to take effect: