Commit 3e4b1430 authored by Dave Cridland's avatar Dave Cridland Committed by daryl herzmann

OF-1437 Try to stop sessions having their routes removed (#938)

* OF-1437 Try to stop sessions having their routes removed

This patch adds a lot of debug logging, plus stops the
console NPE'ing when you try to view a detached session.

It also detaches a session before trying to reattach it, to
avoid it being unrouted when the connection is closed.

* OF-1437 Address comments from Guus

* Don't use toString() in debug logging statements.
* Debug log previd and h values.
parent 4db3374e
...@@ -449,11 +449,17 @@ public abstract class LocalSession implements Session { ...@@ -449,11 +449,17 @@ public abstract class LocalSession implements Session {
@Override @Override
public String getHostAddress() throws UnknownHostException { public String getHostAddress() throws UnknownHostException {
if (conn == null) {
throw new UnknownHostException("Detached session");
}
return conn.getHostAddress(); return conn.getHostAddress();
} }
@Override @Override
public String getHostName() throws UnknownHostException { public String getHostName() throws UnknownHostException {
if (conn == null) {
throw new UnknownHostException("Detached session");
}
return conn.getHostName(); return conn.getHostName();
} }
......
...@@ -150,6 +150,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -150,6 +150,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
public boolean addClientRoute(JID route, LocalClientSession destination) { public boolean addClientRoute(JID route, LocalClientSession destination) {
boolean added; boolean added;
boolean available = destination.getPresence().isAvailable(); boolean available = destination.getPresence().isAvailable();
Log.debug("Adding client route {}", route);
localRoutingTable.addRoute(new DomainPair("", route.toString()), destination); localRoutingTable.addRoute(new DomainPair("", route.toString()), destination);
if (destination.getAuthToken().isAnonymous()) { if (destination.getAuthToken().isAnonymous()) {
Lock lockAn = CacheFactory.getLock(route.toString(), anonymousUsersCache); Lock lockAn = CacheFactory.getLock(route.toString(), anonymousUsersCache);
...@@ -946,6 +947,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -946,6 +947,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
lock.unlock(); lock.unlock();
} }
} }
Log.debug("Removing client route {}", route);
localRoutingTable.removeRoute(new DomainPair("", route.toString())); localRoutingTable.removeRoute(new DomainPair("", route.toString()));
return clientRoute != null; return clientRoute != null;
} }
......
...@@ -206,6 +206,7 @@ public class StreamManager { ...@@ -206,6 +206,7 @@ public class StreamManager {
} }
private void startResume(String namespace, String previd, long h) { private void startResume(String namespace, String previd, long h) {
Log.debug("Attempting resumption for {}, h={}", previd, h);
this.namespace = namespace; this.namespace = namespace;
// Ensure that resource binding has NOT occurred. // Ensure that resource binding has NOT occurred.
if (!allowResume() ) { if (!allowResume() ) {
...@@ -238,6 +239,7 @@ public class StreamManager { ...@@ -238,6 +239,7 @@ public class StreamManager {
return; return;
} }
JID fullJid = new JID(authToken.getUsername(), authToken.getDomain(), resource, true); JID fullJid = new JID(authToken.getUsername(), authToken.getDomain(), resource, true);
Log.debug("Resuming session {}", fullJid);
// Locate existing session. // Locate existing session.
LocalClientSession otherSession = (LocalClientSession)XMPPServer.getInstance().getRoutingTable().getClientRoute(fullJid); LocalClientSession otherSession = (LocalClientSession)XMPPServer.getInstance().getRoutingTable().getClientRoute(fullJid);
...@@ -249,6 +251,7 @@ public class StreamManager { ...@@ -249,6 +251,7 @@ public class StreamManager {
sendError(new PacketError(PacketError.Condition.item_not_found)); sendError(new PacketError(PacketError.Condition.item_not_found));
return; return;
} }
Log.debug("Found existing session, checking status");
// Previd identifies proper session. Now check SM status // Previd identifies proper session. Now check SM status
if (!otherSession.getStreamManager().namespace.equals(namespace)) { if (!otherSession.getStreamManager().namespace.equals(namespace)) {
sendError(new PacketError(PacketError.Condition.unexpected_request)); sendError(new PacketError(PacketError.Condition.unexpected_request));
...@@ -259,8 +262,12 @@ public class StreamManager { ...@@ -259,8 +262,12 @@ public class StreamManager {
return; return;
} }
if (!otherSession.isDetached()) { if (!otherSession.isDetached()) {
Log.debug("Existing session is not detached; detaching.");
Connection oldConnection = otherSession.getConnection();
otherSession.setDetached(); otherSession.setDetached();
oldConnection.close();
} }
Log.debug("Attaching to other session.");
// If we're all happy, disconnect this session. // If we're all happy, disconnect this session.
Connection conn = session.getConnection(); Connection conn = session.getConnection();
session.setDetached(); session.setDetached();
...@@ -283,6 +290,10 @@ public class StreamManager { ...@@ -283,6 +290,10 @@ public class StreamManager {
*/ */
public void sendServerAcknowledgement() { public void sendServerAcknowledgement() {
if(isEnabled()) { if(isEnabled()) {
if (session.isDetached()) {
Log.debug("Session is detached, won't request an ack.");
return;
}
String ack = String.format("<a xmlns='%s' h='%s' />", namespace, serverProcessedStanzas & mask); String ack = String.format("<a xmlns='%s' h='%s' />", namespace, serverProcessedStanzas & mask);
session.deliverRawText( ack ); session.deliverRawText( ack );
} }
......
...@@ -165,6 +165,7 @@ ...@@ -165,6 +165,7 @@
</td> </td>
</tr> </tr>
<% <%
boolean detached = false;
if (currentSess instanceof LocalClientSession) { if (currentSess instanceof LocalClientSession) {
LocalClientSession s = (LocalClientSession)currentSess; LocalClientSession s = (LocalClientSession)currentSess;
...@@ -176,6 +177,7 @@ ...@@ -176,6 +177,7 @@
<td> <td>
<% <%
if (s.isDetached()) { if (s.isDetached()) {
detached = true;
%><fmt:message key="session.details.sm-detached"/><% %><fmt:message key="session.details.sm-detached"/><%
} else if (s.getStreamManager().isEnabled()) { } else if (s.getStreamManager().isEnabled()) {
if (s.getStreamManager().getResume()) { if (s.getStreamManager().getResume()) {
...@@ -343,14 +345,16 @@ ...@@ -343,14 +345,16 @@
<fmt:message key="session.details.hostname" /> <fmt:message key="session.details.hostname" />
</td> </td>
<td> <td>
<% try { %> <%
<%= currentSess.getHostAddress() %> if (detached) { %>
/ <fmt:message key="session.details.sm-detached"/>
<%= currentSess.getHostName() %> <% } else {
<% } catch (java.net.UnknownHostException e) { %> try { %>
Invalid session/connection <%= currentSess.getHostAddress() %> / <%= currentSess.getHostName() %>
<% } %> <% } catch (java.net.UnknownHostException e) { %>
</td> Invalid session/connection
<% }
} %>
</tr> </tr>
</tbody> </tbody>
</table> </table>
...@@ -369,6 +373,7 @@ ...@@ -369,6 +373,7 @@
<th>&nbsp;</th> <th>&nbsp;</th>
<th><fmt:message key="session.details.name" /></th> <th><fmt:message key="session.details.name" /></th>
<th><fmt:message key="session.details.resource" /></th> <th><fmt:message key="session.details.resource" /></th>
<th nowrap><fmt:message key="session.details.node" /></th>
<th nowrap colspan="2"><fmt:message key="session.details.status" /></th> <th nowrap colspan="2"><fmt:message key="session.details.status" /></th>
<th nowrap colspan="2"><fmt:message key="session.details.if_presence" /></th> <th nowrap colspan="2"><fmt:message key="session.details.if_presence" /></th>
<th><fmt:message key="session.details.priority" /></th> <th><fmt:message key="session.details.priority" /></th>
......
...@@ -168,11 +168,17 @@ ...@@ -168,11 +168,17 @@
</td> </td>
<td width="1%" nowrap> <td width="1%" nowrap>
<% try { %> <%
<%= sess.getHostAddress() %> LocalClientSession localSession = (LocalClientSession) sess;
<% } catch (java.net.UnknownHostException e) { %> if (localSession != null && localSession.isDetached()) { %>
Invalid session/connection <fmt:message key="session.details.sm-detached"/>
<% } %> <% } else {
try { %>
<%= sess.getHostAddress() %>
<% } catch (java.net.UnknownHostException e) { %>
Invalid session/connection
<% }
} %>
</td> </td>
<td width="1%" nowrap align="center" style="border-right:1px #ccc solid;"> <td width="1%" nowrap align="center" style="border-right:1px #ccc solid;">
......
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