Skip to content

Commit ed2a82d

Browse files
committed
add download timeout
1 parent a18083e commit ed2a82d

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

docs/env.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
127127

128128
## Compute
129129

130+
- `C2D_DOWNLOAD_TIMEOUT`: Per-file timeout (in seconds) for downloading the algorithm and each input asset during a C2D job. If a download exceeds this timeout, the job fails instead of getting stuck. Defaults to `900` (15 minutes). Example: `900`
131+
130132
The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable is used to configure Docker-based compute environments in Ocean Node. This guide will walk you through the options available for defining `DOCKER_COMPUTE_ENVIRONMENTS` and how to set it up correctly. For configuring compute environments and setting prices for each resource (including pricing units and examples), see [Compute pricing](compute-pricing.md).
131133

132134
Example Configuration

src/components/c2d/compute_engine_docker.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
} from 'fs'
5050
import { pipeline } from 'node:stream/promises'
5151
import { CORE_LOGGER } from '../../utils/logging/common.js'
52+
import { ENVIRONMENT_VARIABLES } from '../../utils/constants.js'
5253
import { AssetUtils } from '../../utils/asset.js'
5354
import { FindDdoHandler } from '../core/handler/ddoHandler.js'
5455
import { OceanNode } from '../../OceanNode.js'
@@ -1694,6 +1695,31 @@ export class C2DEngineDocker extends C2DEngine {
16941695
}
16951696
}
16961697

1698+
private getDownloadTimeoutMs(): number {
1699+
const raw = ENVIRONMENT_VARIABLES.C2D_DOWNLOAD_TIMEOUT.value
1700+
const parsed = raw ? parseInt(raw, 10) : NaN
1701+
if (Number.isFinite(parsed) && parsed > 0) {
1702+
return parsed * 1000
1703+
}
1704+
return 15 * 60 * 1000
1705+
}
1706+
1707+
private async pipelineWithDownloadTimeout(
1708+
source: NodeJS.ReadableStream,
1709+
destination: NodeJS.WritableStream
1710+
): Promise<void> {
1711+
const timeoutMs = this.getDownloadTimeoutMs()
1712+
const controller = new AbortController()
1713+
const timer = setTimeout(() => {
1714+
controller.abort(new Error(`Download timed out after ${timeoutMs / 1000}s`))
1715+
}, timeoutMs)
1716+
try {
1717+
await pipeline(source, destination, { signal: controller.signal })
1718+
} finally {
1719+
clearTimeout(timer)
1720+
}
1721+
}
1722+
16971723
// eslint-disable-next-line require-await
16981724
private async processJob(job: DBComputeJob) {
16991725
CORE_LOGGER.info(
@@ -2883,7 +2909,7 @@ export class C2DEngineDocker extends C2DEngine {
28832909
}
28842910

28852911
if (storage) {
2886-
await pipeline(
2912+
await this.pipelineWithDownloadTimeout(
28872913
(await storage.getReadableStream()).stream,
28882914
createWriteStream(fullAlgoPath)
28892915
)
@@ -2992,7 +3018,7 @@ export class C2DEngineDocker extends C2DEngine {
29923018
const fullPath = jobFolderPath + '/data/inputs/' + fileInfo[0].name
29933019
appendFileSync(configLogPath, `Downloading asset to ${fullPath}\n`)
29943020
try {
2995-
await pipeline(
3021+
await this.pipelineWithDownloadTimeout(
29963022
(await storage.getReadableStream()).stream,
29973023
createWriteStream(fullPath)
29983024
)

src/utils/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ export const ENVIRONMENT_VARIABLES: Record<any, EnvVariable> = {
531531
name: 'PERSISTENT_STORAGE',
532532
value: process.env.PERSISTENT_STORAGE,
533533
required: false
534+
},
535+
C2D_DOWNLOAD_TIMEOUT: {
536+
name: 'C2D_DOWNLOAD_TIMEOUT',
537+
value: process.env.C2D_DOWNLOAD_TIMEOUT,
538+
required: false
534539
}
535540
}
536541
export const CONNECTION_HISTORY_DELETE_THRESHOLD = 300

0 commit comments

Comments
 (0)