One issue could be a different process that is accessing and then resetting the device.
Normally opening a session and performing a login will leave the session in state open until the device is reset or C_Logout() is called.
Maybe you want to try the native PKCS#11 module.