Commit 3e926a78 authored by GregDThomas's avatar GregDThomas Committed by daryl herzmann

OF-1435: Ensure that we start a new thread before calling UserManager… (#942)

* OF-1435: Ensure that we start a new thread before calling UserManager::isRegisteredUser(JID)

* OF-1435: Introduce a Future to highlight that the processing may be performed asynchronously.
parent 8ed00ec5
......@@ -172,7 +172,7 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
try {
// Check if the packet is a disco request or a packet with namespace iq:register
if (packet instanceof IQ) {
if (!engine.process(this, (IQ) packet)) {
if (engine.process(this, (IQ) packet) == null) {
process((IQ) packet);
}
}
......
......@@ -32,6 +32,7 @@ import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.openfire.user.property.DefaultUserPropertyProvider;
import org.jivesoftware.openfire.user.property.UserPropertyProvider;
import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener;
......@@ -411,6 +412,10 @@ public class UserManager implements IQResultListener {
* remote users (i.e. domain does not match local domain) a disco#info request is going
* to be sent to the bare JID of the user.
*
* <p>WARNING: If the supplied JID could be a remote user and the disco#info result packet comes back on the same
* thread as the one the calls this method then it will not be processed, and this method will block for 60 seconds
* by default. To change the timeout, update the system property <code>usermanager.remote-disco-info-timeout-seconds</code>
*
* @param user to JID of the user to check it it's a registered user.
* @return true if the specified JID belongs to a local or remote registered user.
*/
......@@ -444,9 +449,9 @@ public class UserManager implements IQResultListener {
server.getIQRouter().addIQResultListener(iq.getID(), this);
synchronized (user.toBareJID().intern()) {
server.getIQRouter().route(iq);
// Wait for the reply to be processed. Time out in 1 minute.
// Wait for the reply to be processed. Time out in 1 minute by default
try {
user.toBareJID().intern().wait(60000);
user.toBareJID().intern().wait(JiveGlobals.getLongProperty("usermanager.remote-disco-info-timeout-seconds", 60) * JiveConstants.SECOND);
}
catch (InterruptedException e) {
// Do nothing
......
package org.jivesoftware.util;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
* A Future that returns immediately.
*
* @param <T> The type of return value
*/
public class ImmediateFuture<T> implements Future<T> {
private final T value;
/**
* Creates a Future that returns null immediately
*/
public ImmediateFuture() {
this(null);
}
/**
* Creates a Future that returns the supplied value immediately
*
* @param value the value to return
*/
public ImmediateFuture(final T value) {
this.value = value;
}
@Override
public boolean cancel(final boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public T get() {
return value;
}
@Override
public T get(final long timeout, final TimeUnit unit) {
return value;
}
}
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