You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a worker thread is busy with other work and doesn't respond to exit messages from the main thread, it becomes blocked and can stall the sync process. To prevent this, the Airdrop SDK implements a two-tier timeout mechanism.
250
+
251
+
- The **soft timeout**, default of 10 minutes and configurable, sends an exit message to the worker thread, allowing it to gracefully shut down via the `onTimeout` function. How to configure this is shown in the example below.
252
+
- If the worker does not respond within the **hard timeout**, default of 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
+
awaitspawn({
270
+
event,
271
+
initialState,
272
+
workerPath,
273
+
initialDomainMapping,
274
+
options: {
275
+
timeout: 5*1000, // 5 seconds
276
+
isLocalDevelopment: true,
277
+
},
278
+
});
279
+
```
280
+
281
+
This lets you simulate a soft timeout and validate that your worker shuts down.
0 commit comments