Skip to content

fix: query fresh state on timeout for Windows card events#116

Merged
tomkp merged 1 commit into
masterfrom
fix/windows-card-event-timeout-state-111
Feb 18, 2026
Merged

fix: query fresh state on timeout for Windows card events#116
tomkp merged 1 commit into
masterfrom
fix/windows-card-event-timeout-state-111

Conversation

@tomkp
Copy link
Copy Markdown
Owner

@tomkp tomkp commented Feb 18, 2026

Summary

Fixes the remaining issue with Windows card events not firing reliably (#111).

Root cause: The timeout handler was checking dwEventState from the timed-out SCardGetStatusChange call. On Windows, after a timeout, dwEventState may just mirror dwCurrentState (what was passed in) rather than reflecting the actual hardware state. This made the state divergence check ineffective.

Fix: Explicitly query fresh state using SCARD_STATE_UNAWARE when a timeout occurs. This ensures we get the real current hardware state and can detect missed card insert/remove events within ~1 second.

Changes

  • Modified timeout handler in reader_monitor.cpp to query fresh state instead of relying on potentially stale dwEventState
  • Used SCARD_STATE_UNAWARE with zero timeout to force an immediate fresh state query
  • Improved comments explaining the Windows-specific behavior

Test plan

  • All existing unit tests pass (106 tests)
  • ESLint passes
  • TypeScript type checking passes
  • Manual testing on Windows 11 with smart card reader (requires reporter validation)

Fixes #111

The previous timeout handler checked dwEventState from the timed-out
SCardGetStatusChange call. On Windows, this value may just mirror
dwCurrentState rather than reflecting actual hardware state, making
the state divergence check ineffective.

This fix explicitly queries fresh state using SCARD_STATE_UNAWARE
when a timeout occurs, ensuring we detect card insert/remove events
within ~1 second even when Windows PC/SC fails to set
SCARD_STATE_CHANGED correctly.
@tomkp tomkp merged commit 079026f into master Feb 18, 2026
9 checks passed
@tomkp tomkp deleted the fix/windows-card-event-timeout-state-111 branch February 18, 2026 11:40
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.

Windows: card-inserted/card-removed events fire inconsistently

1 participant