MQ

 View Only
Expand all | Collapse all

MQ Close and Disconnect methods hangs forever

  • 1.  MQ Close and Disconnect methods hangs forever

    Posted Tue November 21, 2023 02:18 AM

    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
    ------------------------------


  • 2.  RE: MQ Close and Disconnect methods hangs forever

    IBM Champion
    Posted Wed November 22, 2023 02:44 PM

    > 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.

    Well, looking at your code and reading your description, it looks like the code is waiting for the TCP timeout to happen. I think it is 10 minutes. Therefore, each method called in your code (IsOpen and Close) will have to go through the TCP timeout each time. Also, where is the disconnect call?

    Why are you re-inventing the wheel? Why don't you just let MQ reconnect to the queue manager?

    https://www.ibm.com/docs/en/ibm-mq/9.3?topic=programs-automatic-client-reconnection-in-net

    later

    Roger



    ------------------------------
    Roger Lacroix
    CTO
    Capitalware Inc.
    London ON Canada
    https://capitalware.com
    ------------------------------



  • 3.  RE: MQ Close and Disconnect methods hangs forever

    Posted Thu November 23, 2023 04:42 AM
    Edited by Balaji Patil Thu November 23, 2023 04:48 AM

    Hi Roger,

    Thank you for your response.


    RE: "Why are you re-inventing the wheel? Why don't you just let MQ reconnect to the queue manager?"
          - We're already using the auto-reconnection logic to reconnect to the same queue manager (check the code snippet below), but due to the following reasons, I wrote the reconnection logic in my program.

    Reasons for writing reconnection logic on top of auto-reconnect logic:
    1. This is the part of upgrade project and the old system which is working since last 15 years has the same reconnection logic. So, my client wanted to have similar logic in the upgraded version.
    2. What if auto-reconnection logic failed to reconnect before timing out, how to handle such situation.
    3. The message volume is high (~100/sec) with tight cycle time. Messages will pileup if connection goes down even for a min. It will be very expensive if auto-reconnection takes to time to reconnect/fail.
    4. So, we thought of implementing this logic. 

    var connectionProperties = new Hashtable();
    LogMessage($"ConnectMQ: Start creating MQ Connection(s)", Tracing.LogCategory.Info, Tracing.LogLevel.NormalLow, null);
    connectionProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
    connectionProperties.Add(MQC.HOST_NAME_PROPERTY, MQHostName);
    connectionProperties.Add(MQC.PORT_PROPERTY, MQPort);
    connectionProperties.Add(MQC.CHANNEL_PROPERTY, MQChannel);
    //In case of network issues - reconnect to same queue manager
     if (!string.IsNullOrEmpty(MQHostName))
     {
     connectionProperties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT_Q_MGR);
     connectionProperties.Add(MQC.CONNECTION_NAME_PROPERTY, String.Format("{0}({1})", MQHostName, MQPort));
     }
    
    LogMessage($"ConnectMQ: MQ Location=Remote. MQHostName = {MQHostName} MQPort = {MQPort} MQChannel = {MQChannel}", Tracing.LogCategory.Info, Tracing.LogLevel.NormalLow, null);
                    
     //Start Creating Inbound connection for reading the messages.
    if (MQQueueNameIn != null && MQQueueNameIn.Length > 0)
    {
    LogMessage($"ConnectMQ: Creating queueManagerIn connection", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugMedium, null);
     queueManagerIn = new MQQueueManager(MQManagerName, connectionProperties);
    
    LogMessage($"ConnectMQ: Connecting to queueIn connection", Tracing.LogCategory.Debug, Tracing.LogLevel.DebugMedium, null);
    queueIn = queueManagerIn.AccessQueue(MQQueueNameIn, MQC.MQOO_BROWSE + MQC.MQOO_INPUT_SHARED + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE);
    }

    Thanks,

    Balaji

    ------------------------------
    Balaji Patil
    ------------------------------



  • 4.  RE: MQ Close and Disconnect methods hangs forever

    0