Ensure uncaught exceptions are logged into server error log
Normally these go to stdout, but in daemon mode that is usually the useless /dev/null device. Bug: issue 483 Change-Id: Ida8d0c91744410b316ba32834a2307b10bc312f8 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -91,6 +92,12 @@ public class Daemon extends SiteProgram {
|
|||||||
@Override
|
@Override
|
||||||
public int run() throws Exception {
|
public int run() throws Exception {
|
||||||
mustHaveValidSite();
|
mustHaveValidSite();
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
log.error("Thread " + t.getName() + " threw exception", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (runId != null) {
|
if (runId != null) {
|
||||||
runFile = new File(new File(getSitePath(), "logs"), "gerrit.run");
|
runFile = new File(new File(getSitePath(), "logs"), "gerrit.run");
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import com.google.gerrit.server.util.IdGenerator;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -56,6 +60,15 @@ public class WorkQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WorkQueue.class);
|
||||||
|
private static final UncaughtExceptionHandler LOG_UNCAUGHT_EXCEPTION =
|
||||||
|
new UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
log.error("WorkQueue thread " + t.getName() + " threw exception", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private Executor defaultQueue;
|
private Executor defaultQueue;
|
||||||
private final IdGenerator idGenerator;
|
private final IdGenerator idGenerator;
|
||||||
private final CopyOnWriteArrayList<Executor> queues;
|
private final CopyOnWriteArrayList<Executor> queues;
|
||||||
@@ -137,6 +150,7 @@ public class WorkQueue {
|
|||||||
public Thread newThread(final Runnable task) {
|
public Thread newThread(final Runnable task) {
|
||||||
final Thread t = parent.newThread(task);
|
final Thread t = parent.newThread(task);
|
||||||
t.setName(prefix + "-" + tid.getAndIncrement());
|
t.setName(prefix + "-" + tid.getAndIncrement());
|
||||||
|
t.setUncaughtExceptionHandler(LOG_UNCAUGHT_EXCEPTION);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user