openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Bug: useDaemonLifecycle retry timeout mutates store after unmount

Open Liohtml opened this issue 6 months ago • 3 comments

Summary

app/src/hooks/useDaemonLifecycle.ts — the scheduleRetry setTimeout callback calls setIsRecovering, incrementConnectionAttempts, and resetConnectionAttempts without checking isMountedRef.current first. These mutate external Zustand-like store state on an unmounted component.

Location

app/src/hooks/useDaemonLifecycle.ts — retry useEffect and retryTimeoutRef

Impact

Low — Store mutations after unmount. Can cause React warnings and stale state.

Suggested Fix

Add if (!isMountedRef.current) return; at the top of the setTimeout body in scheduleRetry, before any store mutations.

Liohtml avatar May 16 '26 14:05 Liohtml

I checked the current main branch, and scheduleRetry already has if (!isMountedRef.current) return; at the start of the retry timeout callback, before setIsRecovering, incrementConnectionAttempts, and resetConnectionAttempts.

It looks like the suggested minimal fix is already present. Is the remaining concern about the async case where the component unmounts while daemonHealth.startDaemon() is awaiting, so store updates after the await should also be guarded?

Yong-yuan-X avatar May 17 '26 14:05 Yong-yuan-X

I rechecked current origin/main and the minimal timeout-body issue described here appears to be fixed.

Evidence in app/src/hooks/useDaemonLifecycle.ts:

  • scheduleRetry returns early if !isMountedRef.current before scheduling work.
  • The retry timeout callback also starts with if (!isMountedRef.current) return; before setIsRecovering, incrementConnectionAttempts, or resetConnectionAttempts.
  • The surrounding async paths also have mounted checks before later state updates.

So the issue as written looks stale/resolved. If there is still a concern, I think it should be narrowed to a separate async-after-await path rather than the original retry timeout mutation.

honor2030 avatar May 17 '26 15:05 honor2030

Confirmed: scheduleRetry on current main already guards with if (!isMountedRef.current) return; before store mutations. Closing as already resolved — thanks @Yong-yuan-X and @honor2030 for verifying.

Liohtml avatar May 17 '26 15:05 Liohtml