sim icon indicating copy to clipboard operation
sim copied to clipboard

Fix: Abort fetch requests on timeout in SimStudioClien

Open SyedaAnshrahGillani opened this issue 5 months ago • 2 comments

Summary

This PR addresses a critical resource management and performance issue in the SimStudioClient by implementing proper request abortion for timed-out fetch calls.


Problem

Previously, the executeWorkflow method used Promise.race to handle timeouts. While this approach rejected the timeout promise, the underlying fetch request continued running in the background, leading to:

  • Resource Leaks: Network connections remained open, increasing memory consumption.
  • Performance Degradation: Continued background activity added unnecessary load.
  • Unpredictable Behavior: Late server responses to already timed-out requests could lead to inconsistent client state.

Solution

The method is refactored to use the AbortController API for more robust timeout handling:

  • A new AbortController is created for each fetch request.
  • A setTimeout is used to trigger abortController.abort() after the configured timeout period.
  • The controller’s signal is passed to the fetch options to enable cancellation.
  • clearTimeout is called once the request completes, preventing stale timeouts.
  • Error handling is enhanced to catch AbortError and provide clear messaging for timeout events.

Benefits

  • Improved Resource Management — Cleans up network and memory resources on timeout.
  • Enhanced Performance — Prevents wasteful processing by halting stalled requests.
  • Predictable Behavior — Ensures client-side state remains consistent by terminating timed-out calls.
  • Best Practice Compliance — Aligns with modern JavaScript standards for request cancellation.

SyedaAnshrahGillani avatar Jul 10 '25 21:07 SyedaAnshrahGillani

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jul 10, 2025 9:56pm

vercel[bot] avatar Jul 10 '25 21:07 vercel[bot]

@SyedaAnshrahGillani is attempting to deploy a commit to the Sim Studio Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jul 10 '25 21:07 vercel[bot]