Skip to content

Conversation

@EliseChouleur
Copy link
Contributor

@EliseChouleur EliseChouleur commented Nov 20, 2025

If session's close raises a SessionHandleInvalid error, that just means the session is already closed by other means.
So don't raise an error but just a warn message in this case.

…lid as it means it's already closed

Signed-off-by: Elise Chouleur <elise.chouleur@doctolib.com>
Signed-off-by: Elise Chouleur <elise.chouleur@doctolib.com>
Signed-off-by: Elise Chouleur <elise.chouleur@doctolib.com>
@EliseChouleur EliseChouleur force-pushed the better-handle-drop-error branch from 8887ff1 to 43551e6 Compare November 20, 2025 19:58
@EliseChouleur EliseChouleur marked this pull request as ready for review November 21, 2025 08:09
@hug-dev
Copy link
Member

hug-dev commented Nov 24, 2025

Thanks for the PR!

means the session is already closed by other means

I am wondering if it's possible for the session to be closed by other means if the API has been used only using safe blocks? If not, it could be good to still have this message to show that something unexpected happened?

But maybe I am missing a flow where this could happen!

@wiktor-k
Copy link
Collaborator

If not, it could be good to still have this message to show that something unexpected happened?

Yep, it sounds as if there would be a double close in this scenario, which would be good to have in logs.

I wonder about the use case of other means of closing the session... 👀

@hug-dev
Copy link
Member

hug-dev commented Nov 24, 2025

I implemented something similar than what you propose here as part of #326 but checking explicitly is the session is already closed

@EliseChouleur
Copy link
Contributor Author

EliseChouleur commented Nov 24, 2025

Hi !

This happens to me when I remove the physical token before dropping the session. In this case, the session is automatically closed by the library in charge of this token.
To be correct, I think the session isn't really closed but the handle became invalid, that should be why I don't get the SessionClosed error as you're handling in the PR @hug-dev

@hug-dev
Copy link
Member

hug-dev commented Nov 26, 2025

Would my PR suffice then? That would allow you to explicitly call session.close() and filter on the error on your side?

@EliseChouleur
Copy link
Contributor Author

I wanted to test the behaviour with your PR but the new implementation with the lifetime parameter on the session is a breaking change not compatible with my current implementation with the Pkcs11 context in a mutex and the session in a thread_local ref cell 😅

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.

3 participants