Skip to content

[BUG]: Face scan timeout uses stale state and may incorrectly transition successful scans to error state #1413

@Priyanshu1-62

Description

@Priyanshu1-62

Target file: frontend/nyaysetu-frontend/src/components/auth/FaceLoginModal.jsx

Description

  • The biometric login flow starts a 45-second timeout when face scanning begins.
  • The timeout callback captures the values of step and faceDetected at the moment the timeout is created.
  • The scanning state, being asynchronous in nature, can update after the moment timeout is captured, and timeout callback may still evaluate the outdated values when it executes.
  • This can lead to incorrect timeout error even on successful authentication flow.

Current behavior

  • The timeout callback depends on state values captured when scanning starts:
setTimeout(() => {
    if (interval) clearInterval(interval);
    if (step === 'scanning' && !faceDetected) {
        setStep('error');
        setMessage('Biometric timeout. Signal not acquired.');
    }
 }, 45000);
  • Timeout callback relies on state values captured by the timeout closure.
  • Outdated timeout callbacks can lead to an incorrect timeout flow.

Proposed Solution

  • Manage the timeout lifecycle explicitly using a dedicated ref variable.
  • Store the timeout ID when scanning starts.
  • Clear the timeout immediately when a valid face is detected.
  • Ensure timeout execution only occurs while the current scan session is active.

Benifits

  • Eliminates race conditions caused by stale closures.
  • Improves reliability and predictability of the biometric login flow.
  • Prevents intermittent, hard-to-reproduce authentication failures.

Additional details

  • Labels: GSSoC'2026, type:bug, type:enhancement, frontend
  • I want to work on this issue.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions