dev: added support of client code debugging without disconnection (no more connection/pings validation in server's test mode);

server: improved disconnection logs, fixed some race conditional bugs;
This commit is contained in:
Oleg Agafonov 2024-10-09 16:03:38 +04:00
parent f0c6835d36
commit 8d6ba84556
7 changed files with 39 additions and 35 deletions

View file

@ -54,13 +54,13 @@ public final class Main {
private static final MageVersion version = new MageVersion(Main.class);
// Server threads:
// - worker threads: creates for each connection, controls by maxPoolSize;
// - acceptor threads: processing requests to start a new connection, controls by numAcceptThreads;
// - backlog threads: processing waiting queue if maxPoolSize reached, controls by backlogSize;
// - acceptor threads: processing new connection from a client, controlled by numAcceptThreads;
// - worker threads (server threads): processing income requests from a client, controlled by maxPoolSize;
// - backlog: max size of income queue if maxPoolSize reached, controlled by backlogSize;
// Usage hints:
// - if maxPoolSize reached then new clients will freeze in connection dialog until backlog queue overflow;
// - so for active server must increase maxPoolSize to big value like "max online * 10" or enable worker idle timeout
// - worker idle time will free unused worker thread, so new client can connect;
// - so for active server must increase maxPoolSize to bigger value like "max online * 20"
// - worker idle timeout will free unused worker thread, so new client can connect again;
private static final int SERVER_WORKER_THREAD_IDLE_TIMEOUT_SECS = 5 * 60; // no needs to config, must be enabled for all
// arg settings can be setup by run script or IDE's program arguments like -xxx=yyy
@ -85,6 +85,7 @@ public final class Main {
// - fast game buttons;
// - cheat commands;
// - no deck validation;
// - no connection validation by pings (no disconnects on IDE's debugger usage)
// - load any deck in sideboarding;
// - simplified registration and login (no password check);
// - debug main menu for GUI and rendering testing (must use -debug arg for client app);
@ -342,6 +343,8 @@ public final class Main {
@Override
public void handleConnectionException(Throwable throwable, Client client) {
// called on client disconnect or on failed network (depends on server config's leasePeriod)
String sessionId = client.getSessionId();
Session session = managerFactory.sessionManager().getSession(sessionId).orElse(null);
if (session == null) {
@ -357,7 +360,7 @@ public final class Main {
} else {
sessionInfo.append("[no user]");
}
sessionInfo.append(" at ").append(session.getHost()).append(", sessionId: ").append(session.getId());
sessionInfo.append(" at ").append(session.getHost());
// check disconnection reason
// lease ping is inner jboss feature to check connection status
@ -371,13 +374,13 @@ public final class Main {
} else if (throwable == null) {
// lease timeout (ping), so server lost connection with a client
// must keep tables
logger.info("LOST CONNECTION - " + sessionInfo);
logger.info("LOST CONNECTION (bad network) - " + sessionInfo);
logger.debug("- cause: lease expired");
managerFactory.sessionManager().disconnect(client.getSessionId(), DisconnectReason.LostConnection, true);
} else {
// unknown error
// must keep tables
logger.info("LOST CONNECTION - " + sessionInfo);
logger.info("LOST CONNECTION (unknown) - " + sessionInfo);
logger.debug("- cause: unknown error - " + throwable);
managerFactory.sessionManager().disconnect(client.getSessionId(), DisconnectReason.LostConnection, true);
}
@ -396,7 +399,8 @@ public final class Main {
connector.addInvocationHandler("callback", serverInvocationHandler); // commands processing
// connection monitoring and errors processing
connector.setLeasePeriod(managerFactory.configSettings().getLeasePeriod());
boolean isTestMode = ((MageServerImpl) target).getServerState().isTestMode();
connector.setLeasePeriod(isTestMode ? 3600 * 1000 : managerFactory.configSettings().getLeasePeriod());
connector.addConnectionListener(new MageServerConnectionListener(managerFactory));
}

View file

@ -4,6 +4,7 @@ import mage.MageException;
import mage.players.net.UserData;
import mage.server.managers.ManagerFactory;
import mage.server.managers.SessionManager;
import mage.util.ThreadUtils;
import org.apache.log4j.Logger;
import org.jboss.remoting.callback.InvokerCallbackHandler;
@ -63,8 +64,7 @@ public class SessionManagerImpl implements SessionManager {
if (session != null) {
String errorMessage = session.connectUser(userName, password, restoreSessionId);
if (errorMessage == null) {
logger.info(userName + " connected to server by sessionId " + sessionId
+ (restoreSessionId.isEmpty() ? "" : ", restoreSessionId " + restoreSessionId));
logger.info(userName + " connected to server" + (restoreSessionId.isEmpty() ? "" : " with restored session"));
if (detailsMode) {
logger.info("- details: " + userInfo);
}
@ -153,6 +153,8 @@ public class SessionManagerImpl implements SessionManager {
}
user.showUserMessage("Admin action", "Your session was disconnected by admin");
ThreadUtils.sleep(1000);
logger.warn(user.getName() + " disconnected by admin");
disconnect(userSessionId, DisconnectReason.DisconnectedByAdmin, true);
admin.showUserMessage("Admin result", "User " + user.getName() + " was disconnected");
}

View file

@ -234,6 +234,7 @@ public class UserManagerImpl implements UserManager {
}
if (isBadSession) {
// full disconnect
logger.info(user.getName() + " disconnected due connection problems");
disconnect(user.getId(), DisconnectReason.SessionExpired);
}
break;

View file

@ -127,7 +127,7 @@ public enum ServerMessagesUtil {
private String getServerStatsMessage() {
long current = System.currentTimeMillis();
long hours = ((current - startDate) / (1000 * 60 * 60));
long hours = startDate <= 0 ? 0 : ((current - startDate) / (1000 * 60 * 60));
String updated = new Date().toInstant().atOffset(ZoneOffset.UTC).toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
return String.format("Server uptime: %d hours; max online: %d; active games: %d of %d, tourneys: %d of %d; stats from %s",
hours,