I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 18531f0c authored by zab2's avatar zab2
Browse files

Log close() loops

parent 93df048b
No related branches found
No related tags found
No related merge requests found
...@@ -4,29 +4,41 @@ import java.io.IOException; ...@@ -4,29 +4,41 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.channels.SelectableChannel; import java.nio.channels.SelectableChannel;
import java.util.concurrent.atomic.AtomicBoolean;
import net.i2p.I2PAppContext;
import net.i2p.client.I2PSession; import net.i2p.client.I2PSession;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.util.Log;
/** /**
* Bridge between the full streaming lib and the I2PSocket API * Bridge between the full streaming lib and the I2PSocket API
* *
*/ */
class I2PSocketFull implements I2PSocket { class I2PSocketFull implements I2PSocket {
private Connection _connection; private final Log log;
private Destination _remotePeer; private volatile Connection _connection;
private Destination _localPeer; private final Destination _remotePeer;
private final Destination _localPeer;
private volatile MessageChannel _channel; private volatile MessageChannel _channel;
private final AtomicBoolean _closed = new AtomicBoolean(false);
public I2PSocketFull(Connection con) { public I2PSocketFull(Connection con, I2PAppContext context) {
log = context.logManager().getLog(I2PSocketFull.class);
_connection = con; _connection = con;
if (con != null) { if (con != null) {
_remotePeer = con.getRemotePeer(); _remotePeer = con.getRemotePeer();
_localPeer = con.getSession().getMyDestination(); _localPeer = con.getSession().getMyDestination();
} } else
_remotePeer = _localPeer = null;
} }
public void close() throws IOException { public void close() throws IOException {
if (!_closed.compareAndSet(false,true)) {
// log a trace to find out why
LogUtil.logCloseLoop(log, "I2PSocket",_localPeer,"-->",_remotePeer,_connection);
return;
}
Connection c = _connection; Connection c = _connection;
if (c == null) return; if (c == null) return;
if (c.getIsConnected()) { if (c.getIsConnected()) {
......
...@@ -316,10 +316,7 @@ public class I2PSocketManagerFull implements I2PSocketManager { ...@@ -316,10 +316,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
public void destroySocketManager() { public void destroySocketManager() {
if (!_isDestroyed.compareAndSet(false,true)) { if (!_isDestroyed.compareAndSet(false,true)) {
// shouldn't happen, log a stack trace to find out why it happened // shouldn't happen, log a stack trace to find out why it happened
if (_log.shouldLog(Log.WARN)) { LogUtil.logCloseLoop(_log, "I2PSocketManager", getName());
String log = "over-destroying manager "+getName();
_log.log(Log.WARN,log,new Exception("check stack trace"));
}
return; return;
} }
_connectionManager.setAllowIncomingConnections(false); _connectionManager.setAllowIncomingConnections(false);
......
package net.i2p.client.streaming;
import net.i2p.util.Log;
class LogUtil {
private LogUtil() {}
/**
* logs a loop when closing a resource with level WARN
* @param desc vararg description
* @param log logger for the class we're intersted in
*/
static void logCloseLoop(Log log, Object... desc) {
logCloseLoop(log, Log.WARN, desc);
}
/**
* Logs a close loop when closing a resource
* @param desc vararg description of the resource
* @param log logger to use
* @param level level at which to log
*/
static void logCloseLoop(Log log, int level, Object... desc) {
if (!log.shouldLog(level))
return;
// catenate all toString()s
String descString = "close() loop in";
for (Object o : desc) {
descString += " ";
descString += String.valueOf(o);
}
Exception e = new Exception("check stack trace");
log.log(level,descString,e);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment