Question: How to correctly handle a Session
#243
-
|
Hi ! What is be the best practice to handle a session here ? |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
If there's one active this may be problematic 🤔 can you have a reference to the Session in your struct? CCing @baloo since they've also designed a RustCrypto wrapper around this. |
Beta Was this translation helpful? Give feedback.
-
|
My unfinished prototype can be found here: #192 but essentially, my approach was for the signer to carry a
I don't think the thread-safety garantees or uniqueness of the session are defined at the spec level. I know the two implementation I worked with in the past had varying behavior. One of them you had to opt-in to have thread-safety. |
Beta Was this translation helpful? Give feedback.
-
On my case, the Signer trait in defined insite |
Beta Was this translation helpful? Give feedback.
-
Ack. But |
Beta Was this translation helpful? Give feedback.
-
|
I get this error, but I'll check further |
Beta Was this translation helpful? Give feedback.
-
|
Hmm... sounds like it may need wrapping in an |
Beta Was this translation helpful? Give feedback.
-
|
Unfortunately it's not, I could try to make a small example but it will take me some time. I tried to put Session in an Arc Mutex some time ago but I couldn't manage as Session isn't clonable |
Beta Was this translation helpful? Give feedback.
-
Completely understandable 👍
Hmm... As far as I know neither Arc nor Mutex requires the thing to be cloneable? 🤔 (Arc has a |
Beta Was this translation helpful? Give feedback.
-
|
I checked in Parsec and we open and close sessions just to perform one single operation. I think it's fine to open sessions in parallel but I think that the Login and Logout status of all sessions are affected at the same time |
Beta Was this translation helpful? Give feedback.
-
|
@EliseChouleur did you find a good way to do this :)? |
Beta Was this translation helpful? Give feedback.
-
|
Very sorry for the very long wait, projects prioritization :) But with a fresh vision of the topic (and some discussions with claude 😉) I've changed my implementation to save the session to a thread_local RefCell. Thus, with this implementation, I can easily access my current thread session inside the rustls sign function. |
Beta Was this translation helpful? Give feedback.
Hi @hug-dev, @wiktor-k ,
Very sorry for the very long wait, projects prioritization :)
But with a fresh vision of the topic (and some discussions with claude 😉) I've changed my implementation to save the session to a thread_local RefCell. Thus, with this implementation, I can easily access my current thread session inside the rustls sign function.