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

finalize() without drop()? #150

Open
arjennienhuis opened this issue Jun 10, 2023 · 1 comment
Open

finalize() without drop()? #150

arjennienhuis opened this issue Jun 10, 2023 · 1 comment

Comments

@arjennienhuis
Copy link
Contributor

The only way I can find to "gracefully" stop another thread that is blocking on C_WaitForSlotEvent is to call C_Finalize.

Pkcs11::finalize() is a no-op and Pkcs11Impl::finalize() is only called on drop(). I cannot drop the library if it is being used in another thread.

Is it ok to let Pkcs11::finalize() call Pkcs11Impl::finalize()?

We also need to fix Pkcs11::is_initialized() but that is a separate issue.

@wiktor-k
Copy link
Collaborator

Hmm... Yeah, it looks problematic. I'm not the author of this code but I assume the intention is to allow multiple threads access through Arc to the Impl struct and finalize when all threads are done.

And your point is that you want to call finalize earlier? The problematic part is, the pkcs11 struct assumes that what it holds is an initialized object before finalization. Would it be possible for your code to get all threads to drop their references? That'd deterministically call finalize when the last reference is dropped.

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

No branches or pull requests

2 participants