[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/release] Fix possible NPE and make tests pass again.



commit b2b1bf1d0b2bce7748386b3ecdafec7391890fe6
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Wed Aug 30 20:37:37 2017 +0000

    Fix possible NPE and make tests pass again.
    
    Also, added error logging for indexing process.
---
 .../org/torproject/onionoo/server/NodeIndexer.java | 30 +++++++++++++---------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index db13ed9..5411d0e 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -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,14 +103,18 @@ public class NodeIndexer implements ServletContextListener, Runnable {
 
   @Override
   public void run() {
-    while (this.nodeIndexerThread != null) {
-      this.indexNodeStatuses();
-      try {
-        Thread.sleep(ONE_MINUTE);
-      } catch (InterruptedException e) {
-        /* Nothing that we could handle, just check if there's new data
-         * to index now. */
+    try {
+      while (this.nodeIndexerThread != null) {
+        this.indexNodeStatuses();
+        try {
+          Thread.sleep(ONE_MINUTE);
+        } catch (InterruptedException e) {
+          /* Nothing that we could handle, just check if there's new data
+           * to index now. */
+        }
       }
+    } catch (Throwable th) { // catch all and log
+      log.error("Indexing failed: {}", th.getMessage(), th);
     }
   }
 
@@ -247,11 +251,13 @@ public class NodeIndexer implements ServletContextListener, Runnable {
       newRelaysByContact.get(contact).add(fingerprint);
       newRelaysByContact.get(contact).add(hashedFingerprint);
       String version = entry.getVersion();
-      if (!newRelaysByVersion.containsKey(version)) {
-        newRelaysByVersion.put(version, new HashSet<String>());
+      if (null != version) {
+        if (!newRelaysByVersion.containsKey(version)) {
+          newRelaysByVersion.put(version, new HashSet<String>());
+        }
+        newRelaysByVersion.get(version).add(fingerprint);
+        newRelaysByVersion.get(version).add(hashedFingerprint);
       }
-      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



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits