diff --git a/jpos/src/main/java/org/jpos/iso/ISOServer.java b/jpos/src/main/java/org/jpos/iso/ISOServer.java index fd2733db06..dd8a2db25b 100644 --- a/jpos/src/main/java/org/jpos/iso/ISOServer.java +++ b/jpos/src/main/java/org/jpos/iso/ISOServer.java @@ -32,7 +32,6 @@ import java.time.Duration; import java.util.*; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -97,6 +96,7 @@ private enum PermLogPolicy { private int permitsCount = DEFAULT_MAX_SESSIONS; private static final long SMALL_RELAX = 250; private static final long LONG_RELAX = 5000; + private static final long SHUTDOWN_WAIT = 15000; private final UUID uuid = UUID.randomUUID(); /** @@ -232,6 +232,14 @@ public void shutdown () { shutdownChannels(); } }); + executor.shutdown(); + try { + if (!executor.awaitTermination(SHUTDOWN_WAIT, TimeUnit.MILLISECONDS)) { + executor.shutdownNow(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } private void shutdownServer () { try { @@ -239,8 +247,7 @@ private void shutdownServer () { serverSocket.close (); fireEvent(new ISOServerShutdownEvent(this)); } - executor.awaitTermination(LONG_RELAX, TimeUnit.SECONDS); - } catch (IOException | InterruptedException e) { + } catch (IOException e) { fireEvent(new ISOServerShutdownEvent(this)); Logger.log (new LogEvent (this, "shutdown", e)); } diff --git a/jpos/src/test/java/org/jpos/iso/SslChannelIntegrationTest.java b/jpos/src/test/java/org/jpos/iso/SslChannelIntegrationTest.java index fdb1320e9a..1bf5265140 100644 --- a/jpos/src/test/java/org/jpos/iso/SslChannelIntegrationTest.java +++ b/jpos/src/test/java/org/jpos/iso/SslChannelIntegrationTest.java @@ -38,9 +38,7 @@ import org.jpos.iso.packager.XMLPackager; import org.jpos.util.Logger; import org.jpos.util.SimpleLogListener; -import org.jpos.util.ThreadPool; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** @@ -84,7 +82,7 @@ public void serverSideDisconnect() throws Exception { isoServer.shutdown(); - assertThrows(SocketTimeoutException.class, () -> { + assertThrows(EOFException.class, () -> { clientChannel.receive(); }, "clientChannel should be closed"); }