Skip to content

Commit

Permalink
Merge pull request #444 from internetarchive/fix-dnsjava-selector-thread
Browse files Browse the repository at this point in the history
FetchDNS: Keep dnsjava selector thread out of ToePool
  • Loading branch information
ato committed Nov 27, 2021
2 parents c46cfd1 + 1832c5e commit d63cb9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import org.springframework.context.ApplicationEvent;
import org.springframework.context.Lifecycle;
import org.springframework.context.support.AbstractApplicationContext;
import org.xbill.DNS.DClass;
import org.xbill.DNS.Lookup;

/**
* CrawlController collects all the classes which cooperate to
Expand Down Expand Up @@ -289,10 +287,6 @@ public void start() {

sExit = CrawlStatus.FINISHED_ABNORMAL;

// force creation of DNS Cache now -- avoids CacheCleaner in toe-threads group
// also cap size at 1 (we never wanta cached value; 0 is non-operative)
Lookup.getDefaultCache(DClass.IN).setMaxEntries(1);

reserveMemory = new LinkedList<byte[]>();
for(int i = 0; i < RESERVE_BLOCKS; i++) {
reserveMemory.add(new byte[RESERVE_BLOCK_SIZE]);
Expand Down
13 changes: 13 additions & 0 deletions modules/src/main/java/org/archive/modules/fetcher/FetchDNS.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public class FetchDNS extends Processor {

private static Logger logger = Logger.getLogger(FetchDNS.class.getName());

static {
// cap size at 1 (we never want a cached value; 0 is non-operative)
Lookup.getDefaultCache(DClass.IN).setMaxEntries(1);

// do a dummy lookup to force the creation of dnsjava NIO selector thread
// ensures it doesn't end up in the toe-threads group
try {
new Lookup("localhost").run();
} catch (TextParseException e) {
throw new RuntimeException(e);
}
}

// Defaults.
private short ClassType = DClass.IN;
private short TypeType = Type.A;
Expand Down

0 comments on commit d63cb9a

Please sign in to comment.