Commit b2b1bf1d authored by iwakeh's avatar iwakeh 🌴
Browse files

Fix possible NPE and make tests pass again.

Also, added error logging for indexing process.
parent 2eead2a1
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
   * background thread. */
  public synchronized void startIndexing() {
    if (this.nodeIndexerThread == null) {
      this.nodeIndexerThread = new Thread(this);
      this.nodeIndexerThread = new Thread(this, "Onionoo-Node-Indexer");
      this.nodeIndexerThread.setDaemon(true);
      this.nodeIndexerThread.start();
    }
@@ -103,6 +103,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {

  @Override
  public void run() {
    try {
      while (this.nodeIndexerThread != null) {
        this.indexNodeStatuses();
        try {
@@ -112,6 +113,9 @@ public class NodeIndexer implements ServletContextListener, Runnable {
           * to index now. */
        }
      }
    } catch (Throwable th) { // catch all and log
      log.error("Indexing failed: {}", th.getMessage(), th);
    }
  }

  /** Stop the background process that is periodically reading the node
@@ -247,12 +251,14 @@ public class NodeIndexer implements ServletContextListener, Runnable {
      newRelaysByContact.get(contact).add(fingerprint);
      newRelaysByContact.get(contact).add(hashedFingerprint);
      String version = entry.getVersion();
      if (null != version) {
        if (!newRelaysByVersion.containsKey(version)) {
          newRelaysByVersion.put(version, new HashSet<String>());
        }
        newRelaysByVersion.get(version).add(fingerprint);
        newRelaysByVersion.get(version).add(hashedFingerprint);
      }
    }
    /* This loop can go away once all Onionoo services had their hourly
     * updater write effective families to summary documents at least
     * once.  Remove this code after September 8, 2015. */