Skip to content

Commit 57ba956

Browse files
committed
Timeout handling documentation for Airdrop development
1 parent 6ed2995 commit 57ba956

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

fern/docs/pages/airdrop/data-extraction.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,38 @@ await spawn<DummyExtractorState>({
243243
}
244244
});
245245
```
246+
247+
## Timeout handling
248+
249+
To prevent long-running or blocked worker threads from stalling the sync process, the Airdrop SDK implements a two-tier timeout mechanism.
250+
251+
- The **soft timeout** (default: 10 minutes, configurable) sends an exit message to the worker thread, allowing it to gracefully shut down via the `onTimeout` function.
252+
- If the worker does not respond within the **hard timeout** (default: 13 minutes), it is forcefully terminated.
253+
254+
This mechanism ensures that the snap-in does not hang indefinitely, and the system can recover cleanly in case of stuck or slow code execution.
255+
256+
The most common reason for missed soft timeouts is code that blocks the Node.js event loop. This can prevent the worker thread from processing the exit signal, leading to a hard timeout and forced termination.
257+
258+
To keep the worker thread responsive and ensure soft timeout handling works as intended:
259+
260+
- Avoid long synchronous loops or CPU-heavy operations that block the event loop.
261+
- Use `async/await` for I/O operations such as API calls or file reads.
262+
- Add periodic async breaks in tight loops using `Promise.resolve()`, `setTimeout()`, or `setImmediate()`.
263+
264+
You can find examples of correct timeout-safe code in the [timeout-handling test suite](https://github.com/devrev/adaas-sdk/tree/main/src/tests/timeout-handling).
265+
266+
To test how your snap-in responds to timeouts, you can configure a shorter timeout using the `spawn` function:
267+
268+
```typescript
269+
await spawn({
270+
event,
271+
initialState,
272+
workerPath,
273+
initialDomainMapping,
274+
options: {
275+
timeout: 5 * 1000, // 5 seconds
276+
isLocalDevelopment: true,
277+
},
278+
});
279+
280+
This lets you quickly simulate a soft timeout and validate that your worker shuts down gracefully.

0 commit comments

Comments
 (0)