When you are in your logic that hangs forever, have you collected a Java thread dump to see exactly why your are hanging?
One thing I have noticed with Java IBM MQ programming is you can encounter IBM MQ calls that hang forever in a TCP socket read. The below system property is not documented very well in the IBM MQ manual, but it handles breaking your IBM MQ call out of a stuck TCP socket read. The below example breaks out of the TCP socket read after 15 seconds. From my understanding, the default of a TCP socket read on Linux is to wait forever. This may be your underlying issue, but you may need to collect some more diagnostics to confirm this.
Original Message:
Sent: Mon November 27, 2023 01:29 AM
From: Balaji Patil
Subject: MQ Close and Disconnect methods hangs forever
Hi Andrew, Francois:
Any suggestion on these:
- How to know if the auto-reconnection timed out, will it throw an exception?
- What is the default timeout value, can we set the timeout through the code?
------------------------------
Balaji Patil
Original Message:
Sent: Fri November 24, 2023 06:13 AM
From: Andrew Hickson
Subject: MQ Close and Disconnect methods hangs forever
My expertise of the wrapper layers that provide higher level language support is very limited, however there are very few occasions where the underlying queue manager binding upon which this is all based could appear to "hang forever". In particular, I'm unaware as to the threading model used and what state the HConn was in when the "threading.timer call back method" ran. I thought it might be worth pointing out that an hConn only supports serial MQI usage (see the description of MQCNO_HANDLE_SHARE_BLOCK and MQCNO_HANDLE_SHARE_NO_BLOCK. In the even that the option to block is selected then a call to MQCLOSE under a timer thread while the main worker thread was in a blocking MQI call (typically an MQGET with indefinite/long wait interval) would be expected to appear to "hang forever".
------------------------------
Andrew Hickson
Original Message:
Sent: Fri November 24, 2023 03:33 AM
From: Balaji Patil
Subject: MQ Close and Disconnect methods hangs forever
Hi Francois: Thank you for the code snippet.
Any suggestion on these:
- How to know if the auto-reconnection timed out, will it throw an exception?
- What is the default timeout value, can we set the timeout through the code?
------------------------------
Balaji Patil
Original Message:
Sent: Fri November 24, 2023 03:26 AM
From: Francois Brandelik
Subject: MQ Close and Disconnect methods hangs forever
Replace it with:
if (queueIn != null) { LogMessage($"DisconnectMQ: queueIn is open calling queueIn.close() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null);try { queueIn.Close(); } catch (Exception e) { } finally { queueIn = null; } } if (queueManagerIn != null) { LogMessage($"DisconnectMQ: queueManagerIn is open calling queueManagerIn.Disconnect() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null); try { queueManagerIn.Disconnect(); } catch (Exception e) { } finally { queueManagerIn = null; } }
------------------------------
Francois Brandelik
Original Message:
Sent: Fri November 24, 2023 01:29 AM
From: Balaji Patil
Subject: MQ Close and Disconnect methods hangs forever
Hi Francios, Roger:
Thats exactly what we are trying to achieve.
If the auto-reconnection timed out, we want to execute the manual reconnection logic.
So,
- How to know if the auto-reconnection timed out, will it throw an exception?
- What is the default timeout value, can we set the timeout through the code?
As per your suggestion, I'll remove the following checking:
if (queueIn != null && queueIn.IsOpen) { LogMessage($"DisconnectMQ: queueIn is open calling queueIn.close() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null); queueIn.Close(); } if (queueManagerIn != null && queueManagerIn.IsConnected) { LogMessage($"DisconnectMQ: queueManagerIn is open calling queueManagerIn.Disconnect() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null); queueManagerIn.Disconnect(); }
------------------------------
Balaji Patil
Original Message:
Sent: Thu November 23, 2023 11:18 PM
From: Francois Brandelik
Subject: MQ Close and Disconnect methods hangs forever
I believe his manual re-connection logic was meant to kick in after the MQ automated one had timed out...
------------------------------
Francois Brandelik
Original Message:
Sent: Thu November 23, 2023 03:23 PM
From: Roger Lacroix
Subject: MQ Close and Disconnect methods hangs forever
> I believe the most time spent is in your isOpen check. You already know the connection is shot because you got a connection_broken so checking the isopen method is just a waste of time...
Exactly. Plus, how can an application be faster than MQ's own reconnection logic!
connectionProperties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT_Q_MGR);
Also, why does his code enable MQ reconnection but then want to use his own reconnection code? It is so weird. So, the MQ client library will reconnect, and then his code will force a reconnect; that is a scenario for a memory leak or connection leak.
later
Roger
------------------------------
Roger Lacroix
CTO
Capitalware Inc.
London ON Canada
https://capitalware.com
Original Message:
Sent: Thu November 23, 2023 11:02 AM
From: Francois Brandelik
Subject: MQ Close and Disconnect methods hangs forever
If you are going to close the queue or the connection, why check the isopen method?
Just close / disconnect if the object is not null and set it to null after the close / disconnect call. (use finally of try/catch of the close or disconnect).
I believe the most time spent is in your isOpen check. You already know the connection is shot because you got a connection_broken so checking the isopen method is just a waste of time...
Hope it helps
------------------------------
Francois Brandelik
Original Message:
Sent: Tue November 21, 2023 02:17 AM
From: Balaji Patil
Subject: MQ Close and Disconnect methods hangs forever
We are using a threading.timer call back method to reestablish connection when MQ goes down.
The below call is never completing, it hangs forever. No exception or crash reported to the calling thread:
LogMessage($"DisconnectMQ: Start closing all the MQ connections ", Tracing.LogCategory.Info, Tracing.LogLevel.NormalLow, null); //Close all MQ Queue connections try { if (queueIn != null && queueIn.IsOpen) { LogMessage($"DisconnectMQ: queueIn is open calling queueIn.close() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null); queueIn.Close(); } if (queueIn_Delete != null && queueIn_Delete.IsOpen) { LogMessage($"DisconnectMQ: queueIn_Delete is open calling queueOut.close() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null); queueIn_Delete.Close(); } if (queueOut != null && queueOut.IsOpen) { LogMessage($"DisconnectMQ: queueOut is open calling queueOut.close() ", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugLow, null); queueOut.Close(); } } catch (Exception ex) { string message = "DisconnectMQ: Error Caught at CATCH 17, while closing the MQ connections"; LogException(message, ex); }
------------------------------
Balaji Patil
------------------------------