Skip to content

Commit 5601453

Browse files
authored
Merge pull request #659 from internetarchive/adam/handle-bdb-shutdown-interrupts
fix: handle bdb shutdown interrupts
2 parents 61af1d8 + 1ab9b4a commit 5601453

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

commons/src/main/java/org/archive/bdb/StoredQueue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public Iterator<E> iterator() {
9393
@Override
9494
public int size() {
9595
try {
96+
Thread.interrupted();
9697
return Math.max(0,
9798
(int)(tailIndex.get()
9899
- queueMap.firstKey()));

engine/src/main/java/org/archive/crawler/framework/CrawlController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ private boolean shouldContinueCrawling() {
423423
public synchronized void requestCrawlStop() {
424424
if(state == State.STOPPING) {
425425
// second stop request; nudge the threads with interrupts
426-
getToePool().cleanup();
426+
if (getToePool() != null)
427+
getToePool().cleanup();
427428
}
428429
requestCrawlStop(CrawlStatus.ABORTED);
429430
}

modules/src/main/java/org/archive/modules/fetcher/BdbCookieStore.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void addCookieImpl(Cookie cookie) {
134134
} catch (UnsupportedEncodingException e) {
135135
throw new RuntimeException(e); // impossible
136136
}
137-
137+
Thread.interrupted();
138138
if (!cookie.isExpired(new Date())) {
139139
cookies.put(key, cookie);
140140
} else {
@@ -144,7 +144,7 @@ public void addCookieImpl(Cookie cookie) {
144144

145145
public boolean expireCookie(Cookie cookie, Date date) {
146146
byte[] key = sortableKey(cookie).getBytes(StandardCharsets.UTF_8);
147-
147+
Thread.interrupted();
148148
if (cookie.isExpired(date)) {
149149
cookies.remove(key);
150150
return true;
@@ -160,6 +160,7 @@ protected Collection<Cookie> hostSubset(String host) {
160160
char chAfterDelim = (char)(((int)';')+1);
161161
byte[] endKey = (host + chAfterDelim).getBytes("UTF-8");
162162

163+
Thread.interrupted();
163164
SortedMap<byte[], Cookie> submap = cookies.subMap(startKey, endKey);
164165
return submap.values();
165166

@@ -225,6 +226,7 @@ public void setRecoveryCheckpoint(Checkpoint recoveryCheckpoint) {
225226

226227
@Override
227228
public void clear() {
229+
Thread.interrupted();
228230
cookies.clear();
229231
}
230232

@@ -234,6 +236,7 @@ public void clear() {
234236
@Override
235237
public List<Cookie> getCookies() {
236238
if (cookies != null) {
239+
Thread.interrupted();
237240
return new RestrictedCollectionWrappedList<Cookie>(cookies.values());
238241
} else {
239242
return null;

0 commit comments

Comments
 (0)