Commit 02c22eaa authored by Guus der Kinderen's avatar Guus der Kinderen Committed by daryl herzmann

When closing a session, log why. (#1044)

parent 512ca39e
...@@ -16,16 +16,16 @@ ...@@ -16,16 +16,16 @@
package org.jivesoftware.openfire; package org.jivesoftware.openfire;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* A channel provides a mechanism to queue work units for processing. Each work unit is * A channel provides a mechanism to queue work units for processing. Each work unit is
* encapsulated as a ChannelMessage, and processing of each message is performed by a * encapsulated as a ChannelMessage, and processing of each message is performed by a
...@@ -83,23 +83,34 @@ public class Channel<T extends Packet> { ...@@ -83,23 +83,34 @@ public class Channel<T extends Packet> {
* *
* @param packet an XMPP packet to add to the channel for processing. * @param packet an XMPP packet to add to the channel for processing.
*/ */
public void add(final T packet) { public void add( final T packet )
Runnable r = new Runnable() { {
Runnable r = new Runnable()
{
@Override @Override
public void run() { public void run()
try { {
channelHandler.process(packet); try
{
channelHandler.process( packet );
} }
catch (Exception e) { catch ( Exception e )
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); {
Log.error( LocaleUtils.getLocalizedString( "admin.error" ), e );
try {
Session session = SessionManager.getInstance().getSession(packet.getFrom()); try
{
Session session = SessionManager.getInstance().getSession( packet.getFrom() );
if ( session != null )
{
Log.debug( "Closing session of '{}': {}", packet.getFrom(), session );
session.close(); session.close();
} }
catch (Exception e1) { }
Log.error(e1.getMessage(), e1); catch ( Exception e1 )
} {
Log.error( "Unexpected exception while trying to close session of '{}'.", packet.getFrom(), e1 );
}
} }
} }
}; };
......
...@@ -175,6 +175,7 @@ class LocalSessionManager { ...@@ -175,6 +175,7 @@ class LocalSessionManager {
for (LocalIncomingServerSession session : incomingServerSessions.values()) { for (LocalIncomingServerSession session : incomingServerSessions.values()) {
try { try {
if (session.getLastActiveDate().getTime() < deadline) { if (session.getLastActiveDate().getTime() < deadline) {
Log.debug( "ServerCleanupTask is closing an incoming server session that has been idle for a long time. Last active: {}. Session to be closed: {}", session.getLastActiveDate(), session );
session.close(); session.close();
} }
} }
......
...@@ -192,6 +192,7 @@ public class PresenceRouter extends BasicModule { ...@@ -192,6 +192,7 @@ public class PresenceRouter extends BasicModule {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
Session session = sessionManager.getSession(packet.getFrom()); Session session = sessionManager.getSession(packet.getFrom());
if (session != null) { if (session != null) {
Log.debug( "Closing session of '{}': {}", packet.getFrom(), session );
session.close(); session.close();
} }
} }
......
...@@ -149,6 +149,7 @@ public class ExternalComponentManager { ...@@ -149,6 +149,7 @@ public class ExternalComponentManager {
String domain = subdomain + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain(); String domain = subdomain + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain();
Session session = SessionManager.getInstance().getComponentSession(domain); Session session = SessionManager.getInstance().getComponentSession(domain);
if (session != null) { if (session != null) {
Log.debug( "Closing session for external component '{}' as the domain is being blocked. Affected session: {}", domain, session );
session.close(); session.close();
} }
} }
...@@ -486,6 +487,7 @@ public class ExternalComponentManager { ...@@ -486,6 +487,7 @@ public class ExternalComponentManager {
for (ComponentSession session : SessionManager.getInstance().getComponentSessions()) { for (ComponentSession session : SessionManager.getInstance().getComponentSessions()) {
for (String domain : session.getExternalComponent().getSubdomains()) { for (String domain : session.getExternalComponent().getSubdomains()) {
if (!canAccess(domain)) { if (!canAccess(domain)) {
Log.debug( "Closing session for external component '{}' as a changed permission policy is taken into effect. Affected session: {}", domain, session );
session.close(); session.close();
break; break;
} }
......
...@@ -129,7 +129,7 @@ public class IQBindHandler extends IQHandler { ...@@ -129,7 +129,7 @@ public class IQBindHandler extends IQHandler {
int conflictCount = oldSession.incrementConflictCount(); int conflictCount = oldSession.incrementConflictCount();
if (conflictCount > conflictLimit) { if (conflictCount > conflictLimit) {
// Kick out the old connection that is conflicting with the new one Log.debug( "Kick out an old connection that is conflicting with a new one. Old session: {}", oldSession );
StreamError error = new StreamError(StreamError.Condition.conflict); StreamError error = new StreamError(StreamError.Condition.conflict);
oldSession.deliverRawText(error.toXML()); oldSession.deliverRawText(error.toXML());
oldSession.close(); oldSession.close();
......
...@@ -327,6 +327,7 @@ public class HttpBindServlet extends HttpServlet { ...@@ -327,6 +327,7 @@ public class HttpBindServlet extends HttpServlet {
} }
finally { finally {
if (bindingError.getErrorType() == BoshBindingError.Type.terminate) { if (bindingError.getErrorType() == BoshBindingError.Type.terminate) {
Log.debug( "Closing session due to error: {}. Affected session: {}", bindingError, session );
session.close(); session.close();
} }
} }
......
...@@ -128,6 +128,7 @@ public class HttpSessionManager { ...@@ -128,6 +128,7 @@ public class HttpSessionManager {
Log.info( "Stopping instance" ); Log.info( "Stopping instance" );
inactivityTask.cancel(); inactivityTask.cancel();
for (HttpSession session : sessionMap.values()) { for (HttpSession session : sessionMap.values()) {
Log.debug( "Closing as session manager instance is being stopped: {}", session );
session.close(); session.close();
} }
sessionMap.clear(); sessionMap.clear();
...@@ -350,14 +351,14 @@ public class HttpSessionManager { ...@@ -350,14 +351,14 @@ public class HttpSessionManager {
try { try {
long lastActive = currentTime - session.getLastActivity(); long lastActive = currentTime - session.getLastActivity();
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Session was last active " + lastActive + " ms ago: " + session.getAddress()); Log.debug("Session was last active {} ms ago: {}", lastActive, session );
} }
if (lastActive > session.getInactivityTimeout() * JiveConstants.SECOND) { if (lastActive > session.getInactivityTimeout() * JiveConstants.SECOND) {
Log.info("Closing idle session: " + session.getAddress()); Log.info("Closing idle session: {}", session);
session.close(); session.close();
} }
} catch (Exception e) { } catch (Exception e) {
Log.error("Failed to determine idle state for session: " + session, e); Log.error("Failed to determine idle state for session: {}", session, e);
} }
} }
} }
......
...@@ -184,7 +184,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -184,7 +184,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
if (sessions != null) { if (sessions != null) {
Session session = sessions.remove(streamID); Session session = sessions.remove(streamID);
if (session != null) { if (session != null) {
// Close the session Log.debug( "Closing session: {}", session );
session.close(); session.close();
} }
} }
......
...@@ -101,6 +101,7 @@ class BlockingReadingMode extends SocketReadingMode { ...@@ -101,6 +101,7 @@ class BlockingReadingMode extends SocketReadingMode {
Log.debug("Logging off " + socketReader.session.getAddress() + " on " + socketReader.connection); Log.debug("Logging off " + socketReader.session.getAddress() + " on " + socketReader.connection);
} }
try { try {
Log.debug( "Closing session: {}", socketReader.session );
socketReader.session.close(); socketReader.session.close();
} }
catch (Exception e) { catch (Exception e) {
......
...@@ -64,10 +64,12 @@ public class ComponentStanzaHandler extends StanzaHandler { ...@@ -64,10 +64,12 @@ public class ComponentStanzaHandler extends StanzaHandler {
if ("handshake".equals(tag)) { if ("handshake".equals(tag)) {
// External component is trying to authenticate // External component is trying to authenticate
if (!((LocalComponentSession) session).authenticate(doc.getStringValue())) { if (!((LocalComponentSession) session).authenticate(doc.getStringValue())) {
Log.debug( "Closing session that failed to authenticate: {}", session );
session.close(); session.close();
} }
return true; return true;
} else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) { } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
Log.debug( "Closing session because of received stream error {}. Affected session: {}", doc.asXML(), session );
session.close(); session.close();
return true; return true;
} else if ("bind".equals(tag)) { } else if ("bind".equals(tag)) {
......
...@@ -24,6 +24,8 @@ import org.jivesoftware.openfire.multiplex.MultiplexerPacketHandler; ...@@ -24,6 +24,8 @@ import org.jivesoftware.openfire.multiplex.MultiplexerPacketHandler;
import org.jivesoftware.openfire.multiplex.Route; import org.jivesoftware.openfire.multiplex.Route;
import org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession; import org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
...@@ -38,6 +40,8 @@ import org.xmpp.packet.Presence; ...@@ -38,6 +40,8 @@ import org.xmpp.packet.Presence;
*/ */
public class MultiplexerStanzaHandler extends StanzaHandler { public class MultiplexerStanzaHandler extends StanzaHandler {
private static final Logger Log = LoggerFactory.getLogger( MultiplexerStanzaHandler.class );
/** /**
* Handler of IQ packets sent from the Connection Manager to the server. * Handler of IQ packets sent from the Connection Manager to the server.
*/ */
...@@ -112,10 +116,12 @@ public class MultiplexerStanzaHandler extends StanzaHandler { ...@@ -112,10 +116,12 @@ public class MultiplexerStanzaHandler extends StanzaHandler {
return true; return true;
} else if ("handshake".equals(tag)) { } else if ("handshake".equals(tag)) {
if (!((LocalConnectionMultiplexerSession) session).authenticate(doc.getStringValue())) { if (!((LocalConnectionMultiplexerSession) session).authenticate(doc.getStringValue())) {
Log.debug( "Closing session that failed to authenticate: {}", session );
session.close(); session.close();
} }
return true; return true;
} else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) { } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
Log.debug( "Closing session because of received stream error {}. Affected session: {}", doc.asXML(), session );
session.close(); session.close();
return true; return true;
} }
......
...@@ -475,6 +475,7 @@ public class SASLAuthentication { ...@@ -475,6 +475,7 @@ public class SASLAuthentication {
session.setSessionData("authRetries", retries); session.setSessionData("authRetries", retries);
if (retries >= JiveGlobals.getIntProperty("xmpp.auth.retries", 3) ) { if (retries >= JiveGlobals.getIntProperty("xmpp.auth.retries", 3) ) {
// Close the connection // Close the connection
Log.debug( "Closing session that failed to authenticate {} times: {}", retries, session );
session.close(); session.close();
} }
} }
......
...@@ -152,6 +152,7 @@ public abstract class StanzaHandler { ...@@ -152,6 +152,7 @@ public abstract class StanzaHandler {
if (stanza.equals("</stream:stream>")) { if (stanza.equals("</stream:stream>")) {
if (session != null) { if (session != null) {
session.getStreamManager().formalClose(); session.getStreamManager().formalClose();
Log.debug( "Closing session as an end-of-stream was received: {}", session );
session.close(); session.close();
} }
return; return;
...@@ -304,6 +305,7 @@ public abstract class StanzaHandler { ...@@ -304,6 +305,7 @@ public abstract class StanzaHandler {
} }
if (packet.getID() == null && JiveGlobals.getBooleanProperty("xmpp.server.validation.enabled", false)) { if (packet.getID() == null && JiveGlobals.getBooleanProperty("xmpp.server.validation.enabled", false)) {
// IQ packets MUST have an 'id' attribute so close the connection // IQ packets MUST have an 'id' attribute so close the connection
Log.debug( "Closing session, as it sent us an IQ packet that has no ID attribute: {}. Affected session: {}", packet.toXML(), session );
StreamError error = new StreamError(StreamError.Condition.invalid_xml); StreamError error = new StreamError(StreamError.Condition.invalid_xml);
session.deliverRawText(error.toXML()); session.deliverRawText(error.toXML());
session.close(); session.close();
...@@ -313,8 +315,7 @@ public abstract class StanzaHandler { ...@@ -313,8 +315,7 @@ public abstract class StanzaHandler {
} }
else { else {
if (!processUnknowPacket(doc)) { if (!processUnknowPacket(doc)) {
Log.warn(LocaleUtils.getLocalizedString("admin.error.packet.tag") + Log.warn(LocaleUtils.getLocalizedString("admin.error.packet.tag") + doc.asXML() + ". Closing session: " + session);
doc.asXML());
session.close(); session.close();
} }
} }
......
...@@ -89,12 +89,14 @@ public class RemoteServerManager { ...@@ -89,12 +89,14 @@ public class RemoteServerManager {
addConfiguration(config); addConfiguration(config);
// Check if the remote server was connected and proceed to close the connection // Check if the remote server was connected and proceed to close the connection
for (Session session : SessionManager.getInstance().getIncomingServerSessions(domain)) { for (Session session : SessionManager.getInstance().getIncomingServerSessions(domain)) {
Log.debug( "Closing session for domain '{}' as the domain is being blocked. Affected session: {}", domain, session );
session.close(); session.close();
} }
// Can't just lookup a single remote server anymore, so check them all. // Can't just lookup a single remote server anymore, so check them all.
for (DomainPair domainPair : SessionManager.getInstance().getOutgoingDomainPairs()) { for (DomainPair domainPair : SessionManager.getInstance().getOutgoingDomainPairs()) {
if (domainPair.getRemote().equals(domain)) { if (domainPair.getRemote().equals(domain)) {
Session session = SessionManager.getInstance().getOutgoingServerSession(domainPair); Session session = SessionManager.getInstance().getOutgoingServerSession(domainPair);
Log.debug( "Closing (domain-pair) session for domain '{}' as the domain is being blocked. Affected session: {}", domain, session );
session.close(); session.close();
} }
} }
...@@ -348,6 +350,7 @@ public class RemoteServerManager { ...@@ -348,6 +350,7 @@ public class RemoteServerManager {
for (String hostname : SessionManager.getInstance().getIncomingServers()) { for (String hostname : SessionManager.getInstance().getIncomingServers()) {
if (!canAccess(hostname)) { if (!canAccess(hostname)) {
for (Session session : SessionManager.getInstance().getIncomingServerSessions(hostname)) { for (Session session : SessionManager.getInstance().getIncomingServerSessions(hostname)) {
Log.debug( "Closing session for hostname '{}' as a changed permission policy is taken into effect. Affected session: {}", hostname, session );
session.close(); session.close();
} }
} }
...@@ -355,6 +358,7 @@ public class RemoteServerManager { ...@@ -355,6 +358,7 @@ public class RemoteServerManager {
for (DomainPair domainPair : SessionManager.getInstance().getOutgoingDomainPairs()) { for (DomainPair domainPair : SessionManager.getInstance().getOutgoingDomainPairs()) {
if (!canAccess(domainPair.getRemote())) { if (!canAccess(domainPair.getRemote())) {
Session session = SessionManager.getInstance().getOutgoingServerSession(domainPair); Session session = SessionManager.getInstance().getOutgoingServerSession(domainPair);
Log.debug( "Closing session as a changed permission policy is taken into effect. Affected session: {}", session );
session.close(); session.close();
} }
} }
......
...@@ -181,6 +181,7 @@ class LocalRoutingTable { ...@@ -181,6 +181,7 @@ class LocalRoutingTable {
Session session = (Session) route; Session session = (Session) route;
try { try {
if (session.getLastActiveDate().getTime() < deadline) { if (session.getLastActiveDate().getTime() < deadline) {
Log.debug( "ServerCleanupTask is closing an outgoing server session that has been idle for a long time. Last active: {}. Session to be closed: {}", session.getLastActiveDate(), session );
session.close(); session.close();
} }
} }
......
...@@ -280,7 +280,7 @@ public class StreamManager { ...@@ -280,7 +280,7 @@ public class StreamManager {
session.setDetached(); session.setDetached();
// Connect new session. // Connect new session.
otherSession.reattach(conn, h); otherSession.reattach(conn, h);
// Perform resumption on new session. Log.debug( "Perform resumption on session {}. Closing session {}", otherSession, session );
session.close(); session.close();
} }
...@@ -405,7 +405,7 @@ public class StreamManager { ...@@ -405,7 +405,7 @@ public class StreamManager {
Log.debug( "Received acknowledgement from client: h={}", h ); Log.debug( "Received acknowledgement from client: h={}", h );
if (!validateClientAcknowledgement(h)) { if (!validateClientAcknowledgement(h)) {
Log.warn( "Closing client session. Client acknowledges stanzas that we didn't send! Client Ack h: {}, our last stanza: {}", h, unacknowledgedServerStanzas.getLast().x ); Log.warn( "Closing client session. Client acknowledges stanzas that we didn't send! Client Ack h: {}, our last stanza: {}, affected session: {}", h, unacknowledgedServerStanzas.getLast().x, session );
final StreamError error = new StreamError( StreamError.Condition.undefined_condition, "You acknowledged stanzas that we didn't send. Your Ack h: " + h + ", our last stanza: " + unacknowledgedServerStanzas.getLast().x ); final StreamError error = new StreamError( StreamError.Condition.undefined_condition, "You acknowledged stanzas that we didn't send. Your Ack h: " + h + ", our last stanza: " + unacknowledgedServerStanzas.getLast().x );
session.deliverRawText( error.toXML() ); session.deliverRawText( error.toXML() );
session.close(); session.close();
......
...@@ -53,6 +53,7 @@ public class OpenfireWebSocketServlet extends WebSocketServlet { ...@@ -53,6 +53,7 @@ public class OpenfireWebSocketServlet extends WebSocketServlet {
if (session instanceof LocalSession) { if (session instanceof LocalSession) {
Object ws = ((LocalSession) session).getSessionData("ws"); Object ws = ((LocalSession) session).getSessionData("ws");
if (ws != null && (Boolean) ws) { if (ws != null && (Boolean) ws) {
Log.debug( "Closing session as websocket servlet is being destroyed: {}", session );
session.close(); session.close();
} }
} }
......
...@@ -162,6 +162,7 @@ public class XmppWebSocket { ...@@ -162,6 +162,7 @@ public class XmppWebSocket {
} }
if (xmppSession != null) { if (xmppSession != null) {
if (!xmppSession.getStreamManager().getResume()) { if (!xmppSession.getStreamManager().getResume()) {
Log.debug( "Closing session {}", xmppSession );
xmppSession.close(); xmppSession.close();
SessionManager.getInstance().removeSession(xmppSession); SessionManager.getInstance().removeSession(xmppSession);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment