[Mono-dev] Patch: System.ServiceModel.Logger not thread-safe
Uli Hertlein
uli at xdt.com.au
Wed Nov 9 02:03:29 EST 2011
Hi guys,
I believe I've discovered a bug in System.ServiceModel.Logger that can
cause unhandled exceptions when it's used from different threads.
My code occasionally would get tripped up with something like this:
Exception This XmlWriter does not accept Attribute at this state Content.
at System.Xml.XmlTextWriter.WriteStartAttribute (System.String
prefix, System.String localName, System.String namespaceUri) [0x002a8]
in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/XmlTextWriter2.cs:905
at System.Xml.DefaultXmlWriter.WriteStartAttribute (System.String
prefix, System.String localName, System.String ns) [0x00000] in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/DefaultXmlWriter.cs:196
at System.Xml.XmlWriter.WriteAttributeString (System.String prefix,
System.String localName, System.String ns, System.String value)
[0x00000] in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/XmlWriter.cs:264
at System.Xml.XmlWriter.WriteAttributeString (System.String
localName, System.String value) [0x00000] in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/XmlWriter.cs:251
at System.ServiceModel.Logger.TraceCore (TraceEventType eventType,
Int32 id, Boolean hasRelatedActivity, Guid relatedActivity,
System.Object[] data) [0x000fb] in
/Users/uli/src/Mono/mono/mcs/class/System.ServiceModel/System.ServiceModel/Logger.cs:248
at System.ServiceModel.Logger.LogMessage
(System.ServiceModel.Diagnostics.MessageLogTraceRecord log) [0x000ac] in
/Users/uli/src/Mono/mono/mcs/class/System.ServiceModel/System.ServiceModel/Logger.cs:202
at System.ServiceModel.Logger.LogMessage (MessageLogSourceKind
sourceKind, System.ServiceModel.Channels.Message& msg, Int64
maxMessageSize) [0x00029] in
/Users/uli/src/Mono/mono/mcs/class/System.ServiceModel/System.ServiceModel/Logger.cs:170
Unhandled Exception: System.InvalidOperationException: This XmlWriter
does not accept StartTag at this state Error.
at System.Xml.XmlTextWriter.WriteStartElement (System.String prefix,
System.String localName, System.String namespaceUri) [0x0032e] in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/XmlTextWriter2.cs:692
at System.Xml.DefaultXmlWriter.WriteStartElement (System.String
prefix, System.String localName, System.String ns) [0x00000] in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/DefaultXmlWriter.cs:214
at System.Xml.XmlWriter.WriteStartElement (System.String localName,
System.String ns) [0x00000] in
/Users/uli/src/Mono/mono/mcs/class/System.XML/System.Xml/XmlWriter.cs:610
at System.ServiceModel.Logger.TraceCore (TraceEventType eventType,
Int32 id, Boolean hasRelatedActivity, Guid relatedActivity,
System.Object[] data) [0x0002e] in
/Users/uli/src/Mono/mono/mcs/class/System.ServiceModel/System.ServiceModel/Logger.cs:226
at System.ServiceModel.Logger.Log (TraceEventType eventType,
System.String message, System.Object[] args) [0x0000c] in
/Users/uli/src/Mono/mono/mcs/class/System.ServiceModel/System.ServiceModel/Logger.cs:147
Today's debug session showed that it would happen when Logger.LogMessage
is called from different threads (concurrent access to log_writer and
xml_writer), which would eventually happen after some time.
My fix was to lock 'log_writer' before use. A patch against git
mono-2.10 is attached.
Cheers,
/uli
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Logger.diff
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20111109/a4625fd0/attachment-0001.pl
More information about the Mono-devel-list
mailing list