iri icon indicating copy to clipboard operation
iri copied to clipboard

Closing of resources and Thread interrupt

Open marcuslang opened this issue 7 years ago • 5 comments

Hi,

I'm a huge fan of your project and wanted to help a little bit. While going through a code analysis I found two things that can possibly end in a bug or make it harder to analyse bugs. First I've added closing of resources where it was missing. Second I've reinterrupted the Threads after an InterruptedException is thrown. See Don't swallow interrupts for more details on that.

Hope that it helps. Best wishes, Marcus

marcuslang avatar Dec 15 '17 10:12 marcuslang

👎 on all the Thread.interrupt() calls, they all go clearly against the original intentions on how to handle the InterruptedException

gubatron avatar Dec 18 '17 19:12 gubatron

Would you please rebase your changes on top of the current dev branch?

paulhandy avatar Dec 19 '17 19:12 paulhandy

I struggled a little bit with the rebase, but it's done now

marcuslang avatar Dec 20 '17 07:12 marcuslang

Hey,

Sorry for the late response. Can you break this into two PRs? One for each subject.

Thanks

GalRogozinski avatar Mar 08 '18 14:03 GalRogozinski

I think this pull request can be closed without merging with the following explanation:

There are three subjects in this pull request.

  1. Re-interrupt thread after catching the InterruptedException.

    The only difference of re-interrupting is the interrupted status is set again. If the thread itself does not call methods like interrupted() or isInterrupted(), the interrupted status would not affect the thread execution. Even if the thread does call the methods, it would remain the same if no other threads can interrupt it.

    The result of tracing code:

  • Milestone.java No more try-catch of InterruptedException.

  • IXI.java

  • TransactionValidator.java

  • PearlDiver.java

  • ReplicatorSinkProcessor.java

  • TipsManager.java -> TipsSolidifer.java The threads in the above files do not call methods like interrupted() or isInterrupted().

  • ReplicatorSinkPool.java It uses Thread.interrupted() to decide the while loop execution. However, no other threads can interrupt it.

    A simple conclusion: The re-interruption is meaningful only if the thread uses interrupted status to change the flow of thread execution.

  1. Close resource.

    The file FileExportProvider.java is no longer existed.

  2. The other code refinement.

    IRI has changed a lot since the pull request had been proposed. The code refinement had been integrated into IRI with a more elegant and simpler way.

marktwtn avatar Jan 15 '19 17:01 marktwtn