Skip to content

[LOW] 11 orphaned setTimeout callbacks without cleanup across 5 hooks #2323

Description

@v1ktorrr0x

Severity: Low

Source

Multiple hooks — 11 orphaned timeouts total:

File Line(s) What fires
useDeposit.ts 308 refreshSlab() at 2s
useWithdraw.ts 211 refreshSlab() at 2s
useClosePosition.ts 81, 177 setPhase("idle") at 2s (2 instances)
useInitUser.ts 132, 194, 272 refreshSlab() at 2s (3 instances)
useTrade.ts 397 refreshSlab() at 1.2s, 2.2s, 3.5s (3 instances)

Description

All 11 timeouts fire callbacks without clearTimeout on cleanup. For the slab refresh ones, SlabProvider.parseSlab's cancelled guard prevents React state update warnings, but the RPC calls still execute and are discarded. For useClosePosition, the setPhase("idle") call may fire on an unmounted component.

Fix

Store timeout IDs in refs and clear them in a useEffect cleanup:

const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
useEffect(() => () => { if (timeoutRef.current) clearTimeout(timeoutRef.current); }, []);

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions