Skip to content

Stuck thread and no way to cancel when calling BeIDCards#getOneBeIDCard() #9

@ddoaj97

Description

@ddoaj97

Hi,

We are using the eid-commons library in our Java Swing application but we cannot stop background threads that are waiting for an eID card. We want to make it possible to cancel the BeIDCards#getOneBeIDCard() operation when the user closes the UI dialog that asks him to insert an eID or to stop the waiting thread by sending it an interrupt. However after looking into the code of eid-commons both options are currently impossible to implement:

  • Closing the dialog created by BeIDCardsUI#adviseBeIDCardRequired() doesn't have any effect, the getOneBeIDCard() just continues after closing the dialog. It's also not possible to override the behaviour of the DefaultBeIDCardsUI because the adviseBeIDCardRequired() method cannot tell eid-commons to cancel the operation, it's only inteded to show the GUI.
  • Interrupting the background thread to is also not possible because the eid-commons code ignores all interruptions. This is because in the Sleeper#sleepUntilAwakened method the InterruptedException thrown during the Thread#wait() is ignored.

Because of this behaviour its possible to try and sign something multiple times, but as long as no eID is inserted each started thread continues to wait. As soon as the card is inserted all the threads awaken and try to access the eID at the same time, causing exceptions.

I think the easiest solution would be to change the behaviour of the Sleeper#sleepUntilAwakened operation to either rethrow any InterruptedExceptions it might receive or to translate it into a CancelledException.

I have included a simple Java program that demonstrates the problem (see Javadoc on how to reproduce).

EidThreadProblem.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions