JPOS Reconnection Clarification

114 views
Skip to first unread message

vinod kumar

unread,
Jul 4, 2025, 3:42:33 AMJul 4
to jPOS Users
Hi Team,

I have my own custom channel that extends BaseChannel with properties, timeout = 0 but i am using timeout while sending the request request(m, timeout); , now the problem is it is not connecting back when the connection drops to the server, it is just hanging, Will setting the connect-timeout to 5ms resolve the issue, Please help

Alejandro Revilla

unread,
Jul 4, 2025, 8:29:13 AMJul 4
to jpos-...@googlegroups.com
Why do you have a timeout = 0 in your channel?



On Fri, Jul 4, 2025 at 4:42 AM vinod kumar <vinod...@gmail.com> wrote:
Hi Team,

I have my own custom channel that extends BaseChannel with properties, timeout = 0 but i am using timeout while sending the request request(m, timeout); , now the problem is it is not connecting back when the connection drops to the server, it is just hanging, Will setting the connect-timeout to 5ms resolve the issue, Please help

--
--
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/effa9e1b-09ba-4201-83eb-af3cd2f19463n%40googlegroups.com.

vinod kumar

unread,
Jul 4, 2025, 2:21:49 PMJul 4
to jpos-...@googlegroups.com
Isn't timeout for transactions, we are overriding the timeout here like
request(m, timeout);

Doesn't this override the timeout configured in channel XML?

Sent from Gmail Mobile


Andrés Alcarraz

unread,
Jul 4, 2025, 7:50:44 PMJul 4
to jpos-...@googlegroups.com
Those are 2 different timeouts, at different layers.

The timeout configured in the channel is the time the socket read will fail with a java.net.SocketTimeoutException if there is no traffic.

The request timeout is at the mux level, and it is how much the mux will wait for a response before returning null if it doesn't arrive. That is for a specific response to that request. You can have other messages arriving to the channel that are not a response for that request, so mux.request can return null, even if there is incoming traffic over the channel.

Hope this clarifies things.

Andrés Alcarraz

vinod kumar

unread,
Jul 5, 2025, 12:15:25 AMJul 5
to jpos-...@googlegroups.com
Got it, we have connect-timeout for socket timeouts and timeout for mux response timeouts, what happens if connect-timeout is 0, does it just keeps waiting or throws error at some point?

Sent from Gmail Mobile


Andrés Alcarraz

unread,
Jul 5, 2025, 9:03:40 AMJul 5
to jpos-...@googlegroups.com

As apr pointed out, connect-timeout is the time you give a connection to get established.

I meant the timeout at channel level, which is the timeout property of the channel that you said you have set to 0.

----
Enviado desde mi móvil, disculpas por la brevedad.

Sent from my cellphone, I apologize for the brevity.

Andrés Alcarraz.

Andrés Alcarraz

unread,
Jul 5, 2025, 9:05:31 AMJul 5
to jPOS Users

Sorry I mixed threads, apr pointed out that in another one.

----
Enviado desde mi móvil, disculpas por la brevedad.

Sent from my cellphone, I apologize for the brevity.

Andrés Alcarraz.

vinod kumar

unread,
Jul 6, 2025, 6:27:50 AMJul 6
to jpos-...@googlegroups.com
It is still not clear for me, My issue was there were thread hanging waiting for responses and it was timing out as on mux txn level as I had set the dynamic timeouts, now I have updated the connect-timeout to 5sec and timeout, I have kept as it is to 0, as I have the dynamic timeout during mux.request, I have set this dynamic timeout for all types of MTI msg 

Sent from Gmail Mobile


Andrés Alcarraz

unread,
Jul 6, 2025, 6:50:40 AMJul 6
to jpos-...@googlegroups.com

The timeout at channel level controls the time a read operation blocks before it fails without receiving data, that is a property of the channel, that is not overridden by the mux timeout parameter to the mux.request.

The mux.requesst timeout only controls the time the mux will wait for a response to that particular message, it has nothing to do with the socket read operation at channel level.

If you have 0 for channel's timeout, and call mux.receive with a different timeout, the mux will return null, but the channel read's operation will still be waiting forever if nothing comes in. Because that channel doesn't know a thing about the mux.request' timeout parameter. If it doesn't know the other party was disconnected it will wait forever, and that's what it hangs and why Apr suggested the "you want a timeout" article.

Why the request.mux timeout and the channels timeout are decoupled is because of what I said in a previous message, there could be a response arriving for another message, or incoming messages from the other side such as echo messages, the mux.request would return null in that case, but the channel is receiving data, and therefore, as it doesn't know a thing about the mux waiting for a response to a particular message it won't give any exception. That situation is indistinguishable from the one in which there was no incoming message from the channel's perspective if the channel's timeout is 0.

That's why we are telling you to set a timeout greater than 0 to the channel, and we are not talking about the connect timeout.

----
Enviado desde mi móvil, disculpas por la brevedad.

Sent from my cellphone, I apologize for the brevity.

Andrés Alcarraz.

chhil

unread,
Jul 7, 2025, 4:21:55 AMJul 7
to jpos-...@googlegroups.com

In jPOS, the MUX and channel communicate via in/out queues (spaces). It’s important to understand that in the deployment configuration, the MUX and channel in/out queues are inverted to enable bidirectional message flow—i.e., sending and receiving of requests and responses through shared spaces.

When you set the MUX timeout to 0, it tells the MUX to wait indefinitely for a response message that the channel is expected to place in the shared space. However, it’s crucial to realize that the MUX has no awareness of the underlying TCP connection—it operates purely at the messaging layer via these queues.

The MUX does have an isConnected() method, but this merely checks for the presence of a "ready" key in the shared space (typically placed there by the channel). If that key is missing, isConnected() returns false. However, when waiting for a response, the MUX does not re-check whether that ready key has disappeared—meaning it will continue waiting forever if the channel has disconnected. Even after reconnecting it is still waiting for the response and that response will never come and its lost.

Also note: once a blocking mux.request() is issued, there is no way to cancel it. If the response never arrives, the thread will remain blocked indefinitely with your timeout of 0.

If you need non-blocking behavior, you can use the asynchronous request() variant, which takes a response handler. This allows you to process the response if and when it arrives without blocking the thread. But be cautious, in your case you continue to do asynch request and those handlers will just pileup creating a resource leak as the responses never arrive.

See related code in the jPOS source for reference:

🔗 QMUX.java – Lines 199–220


Bottom Line:

Your issue stems from setting the timeout to 0. This is almost always a bad idea. Your timeout value should align with the service-level expectation for receiving a response—e.g., 5 seconds, 30 seconds, etc. If the response arrives within that time, great. If not, your application should treat it as a no-response scenario and proceed with appropriate fallback logic.


-chhil

vinod kumar

unread,
Jul 14, 2025, 4:55:41 AMJul 14
to jpos-...@googlegroups.com
Thanks all for the detailed responses, Its all cleared now.

Sent from Gmail Mobile


vinod kumar

unread,
Jul 14, 2025, 5:48:17 AMJul 14
to jpos-...@googlegroups.com
One more thing, how does the reconnect happens, Is it when the channel timeout or mux timeout and should I add reconnect=true on channalAdaptor, I'm using a custom Channel which extends BaseChannel

Sent from Gmail Mobile

murtuza chhil

unread,
Jul 14, 2025, 8:40:18 AMJul 14
to jPOS Users
Is there a property where you can do reconnect=true ? Please do share how you came up with it?

The receive thread is constantly trying to read data.
On a disconnect it will throw an exception.
This triggers the reconnect after the period you have configured or defaults to a value.

Its highly encouraged to read the free  documentation provided by jPOS.

"If the connection to the remote host breaks, ChannelAdaptor will try to reconnect after a reasonable delay, expressed in millis. If this element is not present, a default of 10 seconds (10000ms) will be used"

-chhil

Andrés Alcarraz

unread,
Jul 14, 2025, 9:56:44 AMJul 14
to jpos-...@googlegroups.com

In addition to Chhil’s as usual excellent and detailed answer.

I will add something regarding this part, just in case.

One more thing, how does the reconnect happens, Is it when the channel timeout or mux timeout

The channel doesn’t know a thing about the timeout of the mux.request, as mentioned before, the mux is decoupled from the channel. They connect through queues, the channel could be receiving other messages, or even a response to the request that for some reason could not be matched by the mux. That would mean that there is traffic over the socket, and thus, the read won’t time out.

The only thing that happens when there is no response before the mux request’s timeout, is that the mux.request will return null.

I hope this helps to clarify a little more, but please, as Chhil suggested, read the docs. The jPOS programmer’s guide is a must-read, and it should be kept as a reference for everyone working with jPOS regularly, it’s only 152 pages long, so it shouldn’t take long. You don’t have to dominate every concept in the first read, but then you will know where to look for something when you need it. And then, if something is missing or difficutlto understand, you can ask with that ground base.

Andrés Alcarraz

Mark Salter

unread,
Jul 14, 2025, 12:17:47 PMJul 14
to jpos-...@googlegroups.com
Can you share what you changed or went with for future users sufferring the same issue (perhaps with this 3rd party)?

-- 
Mark
signature.asc

vinod kumar

unread,
Jul 14, 2025, 12:59:16 PMJul 14
to jpos-...@googlegroups.com
Its our own system, we use jpos as a client, I have added connect-timeout to 5sec and updates timeout from 0 to 5 sec, this is still in testing as of now.

Sent from Gmail Mobile


--
--
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.
Reply all
Reply to author
Forward
0 new messages