From 7aaed8e686e30c9986b6393066f2a86814790efa Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 19 Oct 2008 21:41:07 +0000 Subject: [PATCH] * Client: Prevent a race causing session reconnect --- core/java/src/net/i2p/client/I2PSessionImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/java/src/net/i2p/client/I2PSessionImpl.java b/core/java/src/net/i2p/client/I2PSessionImpl.java index 4d952228b3..5dac3fd5e2 100644 --- a/core/java/src/net/i2p/client/I2PSessionImpl.java +++ b/core/java/src/net/i2p/client/I2PSessionImpl.java @@ -92,6 +92,9 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa /** whether the session connection has already been closed (or not yet opened) */ private boolean _closed; + /** whether the session connection is in the process of being closed */ + private boolean _closing; + /** have we received the current date from the router yet? */ private boolean _dateReceived; /** lock that we wait upon, that the SetDateMessageHandler notifies */ @@ -125,6 +128,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa _log = context.logManager().getLog(I2PSessionImpl.class); _handlerMap = new I2PClientMessageHandlerMap(context); _closed = true; + _closing = false; _producer = new I2CPMessageProducer(context); _availabilityNotifier = new AvailabilityNotifier(); _availableMessages = new HashMap(); @@ -564,6 +568,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa if (_closed) return; if (_log.shouldLog(Log.INFO)) _log.info(getPrefix() + "Destroy the session", new Exception("DestroySession()")); + _closing = true; // we use this to prevent a race if (sendDisconnect) { try { _producer.disconnect(this); @@ -573,6 +578,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa } _availabilityNotifier.stopNotifying(); _closed = true; + _closing = false; closeSocket(); if (_sessionListener != null) _sessionListener.disconnected(this); } @@ -607,7 +613,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa } protected void disconnect() { - if (_closed) return; + if (_closed || _closing) return; if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix() + "Disconnect() called", new Exception("Disconnect")); if (shouldReconnect()) { if (reconnect()) { @@ -656,4 +662,4 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa } protected String getPrefix() { return "[" + (_sessionId == null ? -1 : _sessionId.getSessionId()) + "]: "; } -} \ No newline at end of file +} -- GitLab