GoogleChromeLabs / chromeos_smart_card_connector

Smart Card Connector App for Chrome OS
https://chrome.google.com/webstore/detail/smart-card-connector/khpfeaanjngmcnplbdlpegiifgpfgdco
Apache License 2.0
134 stars 49 forks source link

Test shutdown hangs for 10min if reader is added shortly before #1078

Closed emaxx-google closed 1 year ago

emaxx-google commented 1 year ago

Pseudocode of a reproducer:

  LaunchPcscServer();
  SetSimulatedDevices([{...}]);
  ShutDownPcscServer();  // <-- hangs for 10 min here
emaxx-google commented 1 year ago

The underlying problem, as uncovered by @ViktoriiaKovalova, is a race between the reader initialization and the shutdown logic. Shutdown tries to stop all ongoing USB transfers and then waits until all readers are deinitialized. However, if the init code didn't have a chance to set the USB transfer pointer before that, the cancellation is skipped, and the transfer becomes running until it reaches its 10-minute timeout.

emaxx-google commented 1 year ago

I have a possible patch that works for me locally, but it's a bit of a band-aid fix as ideally the whole multi-threaded model should be redesigned. I'll publish it for the CCID maintainers for the review.