fix(readers): libnfc connection strings, double-close race, and NTP false wake#532
Merged
wizzomafizzo merged 5 commits intomainfrom Feb 9, 2026
Merged
Conversation
…cores libnfc driver names require underscores (e.g. "pn532_i2c", "pn532_uart") but ConnectionString() normalization was stripping them, producing invalid strings like "pn532i2c:/dev/i2c-2" that libnfc cannot recognize. This caused all PN532 I2C and UART connections via libnfc to fail with "cannot open NFC device" after 10 retries. Fixes connection string translation in Open(), Detect(), and both auto-detect functions (detectSerialReaders, detectI2CReaders).
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
On MiSTer (no RTC), the system boots at epoch (1970). When NTP syncs, the wall clock jumps ~56 years. SleepWakeMonitor was interpreting this as a wake-from-sleep event, triggering bulk reader reconnection and causing the "keeps disconnecting" bug. Now Check() skips wake detection when lastCheck was from an unreliable clock (year < 2024), since the elapsed time is meaningless in that case.
The libnfc reader had no mutex protecting its polling and pnd fields. When SleepWakeMonitor triggered reconnection, Close() could race with the polling goroutine, causing a double-close of the C library handle and crashing the service. Add syncutil.RWMutex to protect shared state, following the pattern already used by acr122pcsc and pn532 readers. Close() now nil-checks and nil-outs the device handle under lock before closing it, preventing the double-close race.
…methods Cover Connected, Info, Path, Close (nil device), ReaderID, and validateWriteParameters — all pure-logic paths that don't require the libnfc C library.
…ng Close Capture r.pnd into a local variable under the mutex at the start of writeTag, matching the pattern already used by the polling goroutine. Previously, Close() could nil out r.pnd while writeTag was mid-operation, causing a panic on the next r.pnd method call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pn532_i2c,pn532_uart) butConnectionString()normalization was stripping them, producing invalid strings that libnfc cannot recognize. Extracts translation into testabletoLibnfcConnStr()with full regression coverage.SleepWakeMonitormisinterprets the ~56-year wall clock jump as wake-from-sleep, triggering bulk reader reconnection. Fixed by skipping wake detection when the previous timestamp was from an unreliable clock (year < 2024).pollingandpndfields. ConcurrentClose()calls could double-close the C library handle, crashing the service. Fixed by addingsyncutil.RWMutexprotection following the pattern used by acr122pcsc and pn532 readers.