(
code: string,
maxBuffer: number,
stage: 'validation' | 'execution',
signal: AbortSignal
)
| 140 | } |
| 141 | |
| 142 | private async runCustomScript( |
| 143 | code: string, |
| 144 | maxBuffer: number, |
| 145 | stage: 'validation' | 'execution', |
| 146 | signal: AbortSignal |
| 147 | ): Promise<ExecutionResult> { |
| 148 | const deadline = new AbortController(); |
| 149 | const combined = AbortSignal.any([signal, deadline.signal]); |
| 150 | // Stop waiting even if a custom executor does not cooperate with cancellation. |
| 151 | let detach: (() => void) | undefined; |
| 152 | const pending = new Promise<ExecutionResult>((resolve, reject) => { |
| 153 | detach = onAbort(combined, reject); |
| 154 | this.executor(code, maxBuffer, combined).then(resolve, reject); |
| 155 | }); |
| 156 | try { |
| 157 | return await runWithTimeout(pending, this.timeoutMs, { |
| 158 | onTimeout: () => { |
| 159 | const error = new Error(`Python ${stage} timed out after ${this.timeoutMs}ms`); |
| 160 | deadline.abort(error); |
| 161 | return error; |
| 162 | }, |
| 163 | }); |
| 164 | } finally { |
| 165 | detach?.(); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | private async metadata(code: string, signal?: AbortSignal): Promise<Record<string, unknown>[]> { |
| 170 | const result = await this.execute(code, { maxRows: 10_000 }, signal); |
no test coverage detected