Skip to content

Commit

Permalink
Fix concurency issue when Client was Stopping and torrents were actives
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyraymond committed Apr 25, 2018
1 parent c7e122d commit 9d3ce33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/main/java/org/araymond/joal/core/ttorrent/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,18 @@ public void stop() {
}

public void onTooManyFailedInARaw(final Announcer announcer) {
if (this.stop) {
this.currentlySeedingAnnouncer.remove(announcer);
return;
}

try {
this.lock.writeLock().lock();
this.currentlySeedingAnnouncer.remove(announcer);
this.torrentFileProvider.moveToArchiveFolder(announcer.getTorrentInfoHash());
if (this.stop) {
return;
}

this.addTorrent();
} catch (final NoMoreTorrentsFileAvailableException ignored) {
} finally {
this.currentlySeedingAnnouncer.remove(announcer);
this.lock.writeLock().unlock();
}
}
Expand All @@ -156,11 +157,12 @@ public void onNoMorePeers(final InfoHash infoHash) {
}

public void onTorrentHasStopped(final Announcer stoppedAnnouncer) {
if (this.stop) {
this.currentlySeedingAnnouncer.remove(stoppedAnnouncer);
return;
}
try {
this.lock.writeLock().lock();
if (this.stop) {
return;
}

this.addTorrent();
} catch (final NoMoreTorrentsFileAvailableException ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AnnouncerExecutor(final AnnounceResponseCallback announceResponseCallback
// maximumPoolSize therefore doesn't have any effect.) This may be appropriate when each task is completely independent of others, so tasks
// cannot affect each others execution
final int corePoolSize = 3;
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("announce-thread-%d").build();
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("annnouncer-%d").build();
this.executorService = new ThreadPoolExecutor(corePoolSize, 3, 40, TimeUnit.MINUTES, new LinkedBlockingQueue<>(), threadFactory);
this.currentlyRunning = new HashMap<>(corePoolSize);
}
Expand Down

0 comments on commit 9d3ce33

Please sign in to comment.