i2psnark: Don't mark torrent BAD on I2CP errors (ticket #2725)

Logging:
 - Log to wrapper log after log manager shutdown (ticket #2725)
 - sync methods
Router:
 - Allow clients more time to get disconnect messages at shutdown (ticket #2725)
 - Don't delete router context at shutdown, to prevent a late
   creation of a new app context (ticket #2725)
 - Don't try to delete ping file on Android
javadocs
This commit is contained in:
zzz
2020-04-24 12:44:17 +00:00
parent f2f6dfbf18
commit a7de9a7f24
6 changed files with 119 additions and 22 deletions

View File

@ -98,6 +98,7 @@ public class LogManager implements Flushable {
private final ConcurrentHashMap<Object, Log> _logs;
/** who clears and writes our records */
private LogWriter _writer;
private volatile boolean _shutdown;
/**
* default log level for logs that aren't explicitly controlled
@ -151,6 +152,7 @@ public class LogManager implements Flushable {
// In the router context, we have to rotate to a new log file at startup or the logs.jsp
// page will display the old log.
if (context.isRouterContext()) {
// FIXME don't start thread in constructor
startLogWriter();
} else {
// Only in App Context.
@ -284,6 +286,18 @@ public class LogManager implements Flushable {
* massive logging load as a way of throttling logging threads.
*/
void addRecord(LogRecord record) {
if (_shutdown && !SystemVersion.isAndroid()) {
// Log to wrapper log, for those very-hard-to-debug problems
// that happen after LogManager shutdown
if (_context.isRouterContext() ||
(_displayOnScreen && _onScreenLimit <= record.getPriority())) {
// wrapper logs already do time stamps
boolean showDate = !SystemVersion.hasWrapper();
System.out.print("(shutdown) " + LogRecordFormatter.formatRecord(this, record, showDate));
}
return;
}
if ((!_context.isRouterContext()) && _writer == null)
startLogWriter();
@ -331,7 +345,7 @@ public class LogManager implements Flushable {
/**
* Do not log here, deadlock of LogWriter via rereadConfig().
*/
private void loadConfig() {
private synchronized void loadConfig() {
File cfgFile = _locationFile;
if (!cfgFile.exists()) {
if (!_alreadyNoticedMissingConfig) {
@ -659,7 +673,7 @@ public class LogManager implements Flushable {
}
/** @return success */
public boolean saveConfig() {
public synchronized boolean saveConfig() {
Properties props = createConfig();
try {
DataHelper.storeProps(props, _locationFile);
@ -775,7 +789,8 @@ public class LogManager implements Flushable {
}
}
public void shutdown() {
public synchronized void shutdown() {
_shutdown = true;
if (_writer != null) {
//_log.log(Log.WARN, "Shutting down logger");
// try to prevent out-of-order logging at shutdown