Skip to content

Commit 10309c3

Browse files
authored
[world-local] Fix long-running steps to not time out after 5 minutes (#185)
1 parent 2ae7426 commit 10309c3

File tree

7 files changed

+246
-90
lines changed

7 files changed

+246
-90
lines changed

.changeset/curvy-ravens-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/core": patch
3+
---
4+
5+
Downgrade `@types/node` to v22.19.0

.changeset/heavy-baboons-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/world-local": patch
3+
---
4+
5+
Fix long-running steps to not time out after 5 minutes

packages/core/src/workflow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ export async function runWorkflow(
223223
this.credentials = 'same-origin';
224224
}
225225

226-
if (init?.cache !== undefined) {
227-
this.cache = init.cache;
226+
// `any` cast here because @types/node v22 does not yet have `cache`
227+
if ((init as any)?.cache !== undefined) {
228+
this.cache = (init as any).cache;
228229
} else if (typeof this.cache !== 'string') {
229230
this.cache = 'default';
230231
}

packages/world-local/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@vercel/queue": "0.0.0-alpha.23",
3434
"@workflow/world": "workspace:*",
3535
"ulid": "^3.0.1",
36+
"undici": "^6.19.0",
3637
"zod": "catalog:"
3738
},
3839
"devDependencies": {

packages/world-local/src/queue.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { setTimeout } from 'node:timers/promises';
22
import { JsonTransport } from '@vercel/queue';
33
import { MessageId, type Queue, ValidQueueName } from '@workflow/world';
44
import { monotonicFactory } from 'ulid';
5+
import { Agent } from 'undici';
56
import z from 'zod';
67

78
// For local queue, there is no technical limit on the message visibility lifespan,
@@ -10,6 +11,11 @@ const LOCAL_QUEUE_MAX_VISIBILITY =
1011
parseInt(process.env.WORKFLOW_LOCAL_QUEUE_MAX_VISIBILITY ?? '0', 10) ||
1112
Infinity;
1213

14+
// Create a custom agent with unlimited headers timeout for long-running steps
15+
const httpAgent = new Agent({
16+
headersTimeout: 0,
17+
});
18+
1319
export function createQueue(port?: number): Queue {
1420
const transport = new JsonTransport();
1521
const generateId = monotonicFactory();
@@ -53,11 +59,13 @@ export function createQueue(port?: number): Queue {
5359
let defaultRetriesLeft = 3;
5460
for (let attempt = 0; defaultRetriesLeft > 0; attempt++) {
5561
defaultRetriesLeft--;
62+
5663
const response = await fetch(
5764
`http://localhost:${port}/.well-known/workflow/v1/${pathname}`,
5865
{
5966
method: 'POST',
6067
duplex: 'half',
68+
dispatcher: httpAgent,
6169
headers: {
6270
'x-vqs-queue-name': queueName,
6371
'x-vqs-message-id': messageId,

0 commit comments

Comments
 (0)