Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

jpos3 ISOServer shutdown thread deadlock #631

68 views
Skip to first unread message

Yow Siew Wai

unread,
Dec 31, 2024, 2:35:51 AM12/31/24
to jPOS Users

org.jpos.iso.ISOServer

public void shutdown () { shutdown = true; executor.submit(() -> { Thread.currentThread().setName("ISOServer-shutdown"); shutdownServer(); if (!cfg.getBoolean("keep-channels")) { shutdownChannels(); } }); } private void shutdownServer () { try { if (serverSocket != null) { serverSocket.close (); fireEvent(new ISOServerShutdownEvent(this)); } executor.awaitTermination(LONG_RELAX, TimeUnit.SECONDS); } catch (IOException | InterruptedException e) { fireEvent(new ISOServerShutdownEvent(this)); Logger.log (new LogEvent (this, "shutdown", e)); } }

Executor.awaitTermination(LONG_RELAX, TimeUnit.SECONDS) in shutdownServer() will not succeed until a timeout occurs.

It is trying to wait for its own thread to finish. The executor submits a task, and the task waits for the executor to complete all tasks, resulting in a deadlock. Only after the LONG_RELAX timeout may the code continue to shut down channels.

And LONG_RELAX is 5000 seconds, which is too long before the channels can be shut down.
The suggestion fix is to remove awaitTermination, or to break the shutdown server and shutdown channel into two threads, with only the first completing before the second is called.

Issue created: #631 Please advise.


Yow Siew Wai

unread,
Jan 6, 2025, 1:51:04 AMJan 6
to jPOS Users
tested and working, case close #631 

Alejandro Revilla

unread,
Jan 6, 2025, 11:21:25 AMJan 6
to jpos-...@googlegroups.com
Awesome. That was a very good catch, thank you!



--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jpos-users/3be61429-c952-4848-8358-ac4c95978030n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages