Skip to content
Snippets Groups Projects
Commit c8903b44 authored by iwakeh's avatar iwakeh
Browse files

Solves #19771: keep scheduling even in case of errors.

parent ffdb4985
Branches
No related tags found
No related merge requests found
......@@ -40,8 +40,8 @@ public abstract class CollecTorMain implements Runnable {
log.info("Starting {} module of CollecTor.", module());
try {
startProcessing();
} catch (ConfigurationException | RuntimeException ce) {
log.error("The {} module failed: {}", module(), ce.getMessage(), ce);
} catch (Throwable th) { // Catching all to prevent #19771
log.error("The {} module failed: {}", module(), th.getMessage(), th);
}
log.info("Terminating {} module of CollecTor.", module());
}
......
package org.torproject.collector.cron;
import org.torproject.collector.conf.Configuration;
import org.torproject.collector.conf.ConfigurationException;
import java.util.concurrent.atomic.AtomicInteger;
public class Broken extends CollecTorMain {
static AtomicInteger count = new AtomicInteger(0);
public Broken(Configuration c) {
super(c);
}
@Override
public void startProcessing() throws ConfigurationException {
count.getAndIncrement();
try {
Thread.sleep(10);
} catch (Exception e) { /* ignored */ }
if (count.get() % 2 == 0) {
throw new Error("Throwing an Error.");
} else {
throw new RuntimeException("Throwing an Exception.");
}
}
@Override
public String module() {
return "broken";
}
}
......@@ -57,8 +57,28 @@ public class SchedulerTest {
schedulerField.get(Scheduler.getInstance());
assertTrue(stpe.getQueue().isEmpty());
Scheduler.getInstance().scheduleModuleRuns(ctms, conf);
Scheduler.getInstance().shutdownScheduler();
}
@Test()
public void testScheduleBrokenClass() throws Exception {
Map<Key, Class<? extends CollecTorMain>> ctms = new HashMap<>();
Configuration conf = new Configuration();
conf.load(new ByteArrayInputStream(runConfigProperties.getBytes()));
ctms.put(Key.TorperfActivated, Broken.class);
ctms.put(Key.BridgedescsActivated, Broken.class);
ctms.put(Key.RelaydescsActivated, Broken.class);
ctms.put(Key.ExitlistsActivated, Broken.class);
ctms.put(Key.UpdateindexActivated, Broken.class);
Field schedulerField = Scheduler.class.getDeclaredField("scheduler");
schedulerField.setAccessible(true);
ScheduledThreadPoolExecutor stpe = (ScheduledThreadPoolExecutor)
schedulerField.get(Scheduler.getInstance());
Scheduler.getInstance().scheduleModuleRuns(ctms, conf);
long sysNow = System.currentTimeMillis();
while (System.currentTimeMillis() - sysNow < 120_000) {
try { Thread.sleep(10_000);} catch (Exception e) { /* ignored */ }
}
assertEquals(15, Broken.count.intValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment