Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tray icon Exit #74

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Fix tray icon Exit #74

merged 1 commit into from
Dec 18, 2023

Conversation

GoodSign2017
Copy link
Contributor

@GoodSign2017 GoodSign2017 commented Dec 16, 2023

The Thread is started in SoftU2FDaemon/Program.cs:

            new Thread(() => { daemon.StartIoLoop(_cancellation.Token); }).Start();

This code in U2FLib/U2FHIDDeviceCommunication.cs blocks the Thread execution:

            var result = DeviceIoControl(
                _device,
                IOCTL_SOFTU2F_FILTER_INIT,
                inputBufferPtr, inputBufferLen,
                outputBufferPtr, outputBufferLen,
                ref nTransferred, IntPtr.Zero);

In SoftU2FDaemon/Program.cs this call initiates the cancellation of Thread:

            if (disposing) _cancellation.Cancel();

However, in C# there are no forced Thread cancellations, the cancellations only work as a signal, and if the Thread is blocked by DeviceIoControl, it won't have its event loop run, therefore it doesn't forcefully end.

I have added Register callback to after the Thread cancellation was signaled, and if an exit was requested too, then we shut down the process.

This fixes #72

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.

Daemon v2023-03-20 hangs on exit on 2 out of 3 attempts
2 participants