-
Notifications
You must be signed in to change notification settings - Fork 76
Test parallel access #263
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
base: main
Are you sure you want to change the base?
Test parallel access #263
Conversation
Signed-off-by: daxpedda <[email protected]>
It is indeed reproducible in the CI:
|
Thanks for putting it together! Does Rust run
But if that is the later then I agree that the |
Each test is run in its own thread as part of the same process. See https://doc.rust-lang.org/1.86.0/cargo/commands/cargo-test.html#description.
#[test]
fn test() {
let (pkcs11, slot) = common::init_pins();
let _session = pkcs11.open_rw_session(slot).unwrap();
let (pkcs11, slot) = common::init_pins();
let _session = pkcs11.open_rw_session(slot).unwrap();
} This correctly always returns |
I think this can be an issue on three different levels:
I did not manage to dig into the PKCS#11 specs deep enough, but there is a locking mechanism when you need to access a single token from different threads The softhsm tests with your reproducer crash (I think interface functions do not have enough checks for threaded-access and finalize frees something they expect it will be around):
but kryoptic just fails:
This means that the tests got further, but the first test likely called c_finalize between the second one called the
https://github.com/latchset/kryoptic/blob/main/src/tests/keys.rs#L11 This way, we are able to run the tests in parallel. But we have a bit more control of the token as we call some internals to create separate slot for each test. With generic pkcs11 tokens, you will likely have issues if one thread will be creating objects and the other will be expecting different ones in the single slot, but I think it should still be possible to adjust the tests to work. |
This PR just tests #260 in the CI.
It might be turned into a useful test later down the line when the bug can be reproduced and fixed.