Skip to content

Fixed bug: race condition and memory leak in useEffect data fetching#160

Open
hemannt003 wants to merge 1 commit intoc2siorg:mainfrom
hemannt003:gdb01
Open

Fixed bug: race condition and memory leak in useEffect data fetching#160
hemannt003 wants to merge 1 commit intoc2siorg:mainfrom
hemannt003:gdb01

Conversation

@hemannt003
Copy link
Copy Markdown

@hemannt003 hemannt003 commented Mar 16, 2026

**Fixed bug: race condition and memory leak in useEffect data fetching **

This PR fixes #157

What I changed

  • Updated webapp/src/components/Stack/Stack.jsx
  • Updated webapp/src/components/GdbComponents/BreakPoints/BreakPoints.jsx Updated webapp/src/components/Functions/Functions.jsx Updated webapp/src/components/GdbComponents/MemoryMap/MemoryMap.jsx Also updated webapp/src/components/Terminal/TerminalComp.jsx after searching for other useEffect-triggered API requests

Fix pattern applied

For each affected useEffect with API calls:

  • Created a new AbortController per effect run
  • Passed signal into the request (axios.post(..., { signal }))
  • Added cleanup return () => controller.abort() to cancel in-flight request on dependency change/unmount
  • Guarded state updates with if (!signal.aborted) so aborted/stale responses cannot update UI
  • Ignored abort/cancel errors (AbortError / CanceledError / ERR_CANCELED) and only logged real failures

Result

  • Prevents delayed older responses from overwriting newer state
  • Prevents state updates after unmount (memory leak warning case)
  • Keeps existing UI behavior and state shape unchanged (only fetching logic was touched)

…ncellation and cleanup to all relevant useEffect API flows.

Updated webapp/src/components/Stack/Stack.jsx
Updated webapp/src/components/GdbComponents/BreakPoints/BreakPoints.jsx
Updated webapp/src/components/Functions/Functions.jsx
Updated webapp/src/components/GdbComponents/MemoryMap/MemoryMap.jsx
Also updated webapp/src/components/Terminal/TerminalComp.jsx after searching for other useEffect-triggered API requests
@hemannt003
Copy link
Copy Markdown
Author

Hi @Shubh942 Could you please review the PR whenever you get time and let me know for any changes to be made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] race condition and memory leak in useEffect data fetching

1 participant