Repository navigation
QServer maxSessions behavior in jPOS 3: Allowing multiple connections despite maxSessions=1 #793
Replies: 2 comments
|
Hi, (Reposted: my earlier reply was accidentally sent by email, which broke its formatting, so I deleted it.) From the log format ( Why the second connection is accepted In jPOS 1/2, jPOS 3 replaced the pool with a thread-per-task executor plus a channel.accept(serverSocket);
...
executor.submit(() -> {
try {
permits.acquireUninterruptibly(); // runs later, on the session thread
createSession(channel).run();
} finally {
permits.release();
}
});So with
Net effect: with connections arriving one at a time, you get Enforcing a single connection The proper fix belongs in Until then, you can work around it without patching jPOS by adding a public class SingleSessionGuard implements ISOServerEventListener {
private final AtomicInteger open = new AtomicInteger();
@Override
public void handleISOServerEvent(EventObject ev) {
if (ev instanceof ISOServerAcceptEvent ae) {
if (open.incrementAndGet() > 1) {
try { ((ISOChannel) ae.getISOChannel()).disconnect(); } catch (IOException ignored) { }
}
} else if (ev instanceof ISOServerClientDisconnectEvent) {
open.decrementAndGet();
}
}
}<connection-listener class="com.example.SingleSessionGuard"/>With this, the second client sees a TCP connect followed by an immediate close rather than Connection refused. Because the listening socket is still open, the kernel completes the handshake before jPOS gets a say, so closing the accepted connection is the earliest a listener can act. The counter does run one too high for a while: the dropped channel's task is still parked on the semaphore, so its disconnect event only fires after the first session ends and that task runs (and fails immediately). This is mostly harmless, because during that time the server socket is closed and new connects are refused anyway. The loop reopens the socket only once a permit is free. A legitimate new connection could be wrongly dropped only if it were accepted in the instant between the first session releasing its permit and the parked task grabbing it, which is very unlikely in practice. |
|
Dear @alcarraz Thank you so much for the detailed breakdown and explanation! I implemented the workaround using SingleSessionGuard along with I'll keep an eye on issue #794 and look forward to the fix in a future release. Thanks again for opening the issue and sharing this solution! Good luck to you! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi jPOS community,
I am migrating/running a project on jPOS 3 (using Q2), and I am facing an issue where the
maxSessionsconfiguration onorg.jpos.q2.iso.QServerdoes not seem to restrict concurrent connections as expected.Even though I configured
maxSessionsto1, when a client connection is already established and active, a second connection (liketelnet) can still connect successfully and reachESTABLISHEDstate.Here is my current
QServerXML configuration:All reactions