How to recover from momentary loss of pcscd connection in psycard.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to recover from momentary loss of pcscd connection in psycard.

Ben Mehlman

Using the higher level classes of pyscard (CardRequest, CardService).. if pcscd is shut down temporarily, it results in a ListReadersException.  I would like to catch this exception, retry, and recover from it when pcscd becomes available again.

I tried recreating the CardRequest but that wasn't sufficient to recreate the connection to pcscd.
Is there a correct way to handle this?

Thanks
Ben Mehlman

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to recover from momentary loss of pcscd connection in psycard.

Ludovic Rousseau
Hello,

2016-10-18 3:58 GMT+02:00 Ben Mehlman <[hidden email]>:

Using the higher level classes of pyscard (CardRequest, CardService).. if pcscd is shut down temporarily, it results in a ListReadersException.  I would like to catch this exception, retry, and recover from it when pcscd becomes available again.

I tried recreating the CardRequest but that wasn't sufficient to recreate the connection to pcscd.
Is there a correct way to handle this?

You need to re-establish a connection to the server using SCardEstablishContext().
That may not be easy to do from the high level API.

Why is pcscd shut down?

Bye

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to recover from momentary loss of pcscd connection in psycard.

Ben Mehlman
Thanks Ludovic.

Normally pcscd wouldn't be shut down., and the init/systemd script priorities set up such that pcscd is always running before the client application.   But this is a long running, embedded application where it is conceivable that pcscd might be for example updated during operation.  And yes these updates can be scripted (at the moment we use saltstack) to ensure that the application is restarted after pcscd is restarted, so the error shouldn't (with care) happen.  But we might find this too complicated in the field and want it to be more tolerant of the order in which things are brought up and down.

In my development work where I am running pcscd in the foreground, I saw this error occur and that it results in an easily recognizable exception, so I want to be able to recover from it.  But if the structure of the library doesn't allow it, I can recover from it by having my application exit and be respawned, or have it close all descriptors and re-exec itself if running in the foreground.  But these are heavy handed approaches and I'd hoped to find something more elegant.

Thanks
Ben



On Tue, Oct 18, 2016 at 3:39 AM, Ludovic Rousseau <[hidden email]> wrote:
Hello,

2016-10-18 3:58 GMT+02:00 Ben Mehlman <[hidden email]>:

Using the higher level classes of pyscard (CardRequest, CardService).. if pcscd is shut down temporarily, it results in a ListReadersException.  I would like to catch this exception, retry, and recover from it when pcscd becomes available again.

I tried recreating the CardRequest but that wasn't sufficient to recreate the connection to pcscd.
Is there a correct way to handle this?

You need to re-establish a connection to the server using SCardEstablishContext().
That may not be easy to do from the high level API.

Why is pcscd shut down?

Bye

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle


_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle