Changeset 39b218b


Ignore:
Timestamp:
Oct 16, 2015 2:25:55 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ba1488b
Parents:
b43417bf
Message:

i2psnark: Fix deadlock (ticket #1432)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java

    rb43417bf r39b218b  
    985985    int piece = pp.getPiece();
    986986   
    987     synchronized(wantedPieces)
    988       {
     987    // try/catch outside the synch to avoid deadlock in the catch
     988    try {
     989      synchronized(wantedPieces) {
    989990        Piece p = new Piece(piece);
    990991        if (!wantedPieces.contains(p))
     
    10021003          }
    10031004       
    1004         try
    1005           {
     1005          // try/catch moved outside of synch
    10061006            // this takes forever if complete, as it rechecks
    10071007            if (storage.putPiece(pp))
     
    10291029                return false; // No need to announce BAD piece to peers.
    10301030              }
    1031           }
    1032         catch (IOException ioe)
    1033           {
     1031
     1032        wantedPieces.remove(p);
     1033        wantedBytes -= metainfo.getPieceLength(p.getId());
     1034      }  // synch
     1035    } catch (IOException ioe) {
    10341036            String msg = "Error writing storage (piece " + piece + ") for " + metainfo.getName() + ": " + ioe;
    10351037            _log.error(msg, ioe);
     
    10381040                listener.addMessage("Fatal storage error: Stopping torrent " + metainfo.getName());
    10391041            }
     1042            // deadlock was here
    10401043            snark.stopTorrent();
    10411044            throw new RuntimeException(msg, ioe);
    1042           }
    1043         wantedPieces.remove(p);
    1044         wantedBytes -= metainfo.getPieceLength(p.getId());
    1045       }
     1045    }
    10461046
    10471047    // just in case
Note: See TracChangeset for help on using the changeset viewer.