Skip to content

SIPRequest.ToString() causes Exception on SIPParameters.ToString() #1469

@greco-salvatore

Description

@greco-salvatore

For debugging and logging purposes, i'm using the SIPRequest.ToString() to print the request. In the past i used only SIPRequest.Body property and everything works fine. SIPRequest.ToString() includes also the SIPHeader and sometimes i get this:

[21/10/2025 10:27:57.421] fail: xxxxx_rg.radioManagers.BaseRadioManager[0]
        Message: Collection was modified; enumeration operation may not execute.
        Sender method: AisipWrapper.SipTransport_SIPRequestInTraceEvent
        Notes:    at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
         at SIPSorcery.SIP.SIPParameters.ToString() in C:\Users\greco\git\sipsorcery\src\core\SIP\SIPParameters.cs:line 296
         at SIPSorcery.SIP.SIPViaHeader.ToString() in C:\Users\greco\git\sipsorcery\src\core\SIP\SIPHeader.cs:line 359
         at SIPSorcery.SIP.SIPViaSet.ToString() in C:\Users\greco\git\sipsorcery\src\core\SIP\SIPHeader.cs:line 1316
         at SIPSorcery.SIP.SIPHeader.ToString() in C:\Users\greco\git\sipsorcery\src\core\SIP\SIPHeader.cs:line 2208
         at SIPSorcery.SIP.SIPRequest.ToString() in C:\Users\greco\git\sipsorcery\src\core\SIP\SIPRequest.cs:line 158
         at aisip.AisipWrapper.<>c__DisplayClass108_0.<SipTransport_SIPRequestInTraceEvent>b__0() in C:\xxx\xxx\xxxx\xxxxx\AisipWrapper.cs:line 4449

where there is a concurrent access on the exception line:

        public override string ToString()
        {
            string paramStr = null;

            if (m_dictionary != null)
            {
                //exception
                foreach (KeyValuePair<string, string> param in m_dictionary)
                {
                    if (param.Value != null && param.Value.Trim().Length > 0)
                    {
                        paramStr += TagDelimiter + param.Key + TAG_NAME_VALUE_SEPERATOR + SIPEscape.SIPURIParameterEscape(param.Value);
                    }
                    else
                    {
                        paramStr += TagDelimiter + param.Key;
                    }
                }
            }

            return paramStr;
        }

I've tried to change the m_dictionary to ConcurrentDictionary and adapt the SIPParameters and seems ok and working ok to me. I'll push a pull request shortly

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions