Skip to content

Commit a783efd

Browse files
authored
Merge pull request #1356 from oceanprotocol/add-timeout
Add timeout
2 parents 52300f4 + bbc5656 commit a783efd

4 files changed

Lines changed: 21 additions & 0 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`: Timeout (in seconds) for pulling the algorithm docker image during a C2D job. If the pull exceeds this timeout, the job fails with `PullImageFailed` 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: 11 additions & 0 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'
@@ -1695,6 +1696,15 @@ export class C2DEngineDocker extends C2DEngine {
16951696
}
16961697
}
16971698

1699+
private getImagePullTimeoutMs(): number {
1700+
const raw = ENVIRONMENT_VARIABLES.C2D_DOWNLOAD_TIMEOUT.value
1701+
const parsed = raw ? parseInt(raw, 10) : NaN
1702+
if (Number.isFinite(parsed) && parsed > 0) {
1703+
return parsed * 1000
1704+
}
1705+
return 15 * 60 * 1000
1706+
}
1707+
16981708
// eslint-disable-next-line require-await
16991709
private async processJob(job: DBComputeJob) {
17001710
CORE_LOGGER.info(
@@ -2548,6 +2558,7 @@ export class C2DEngineDocker extends C2DEngine {
25482558
)
25492559
}
25502560

2561+
pullOptions.abortSignal = AbortSignal.timeout(this.getImagePullTimeoutMs())
25512562
const pullStream = await this.docker.pull(job.containerImage, pullOptions)
25522563
await new Promise((resolve, reject) => {
25532564
let wroteStatusBanner = false

src/components/core/utils/statusHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export async function status(
170170
CORE_LOGGER.log(LOG_LEVELS_STR.LEVEL_ERROR, `Error getting c2d clusters: ${error}`)
171171
}
172172
nodeStatus.supportedSchemas = typesenseSchemas.ddoSchemas
173+
} else {
174+
delete nodeStatus.c2dClusters
175+
delete nodeStatus.supportedSchemas
173176
}
174177

175178
if (config.persistentStorage) {

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)