IndexOutOfRangeException in SsdpTraceLogger.WriteLogMessage
BruceMellows opened this issue · comments
This issue is due to using Microsoft.Owin.Hosting.Tracing.DualWriter.Write but is easy and useful to fix in RSSDP.
There is a System.IndexOutOfRangeException with the message "Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader." and the following stack
at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.SyncTextWriter.Write(Char[] buffer, Int32 index, Int32 count)
at Microsoft.Owin.Hosting.Tracing.DualWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.Diagnostics.TextWriterTraceListener.WriteLine(String message)
at System.Diagnostics.TraceListener.WriteLine(String message, String category)
at System.Diagnostics.TraceInternal.WriteLine(String message, String category)
at Rssdp.SsdpTraceLogger.WriteLogMessage(String category, String message)
at Rssdp.SsdpTraceLogger.LogInfo(String message)
at Rssdp.Infrastructure.SsdpDevicePublisherBase.SetRebroadcastAliveNotificationsTimer(TimeSpan minCacheTime)
at Rssdp.Infrastructure.SsdpDevicePublisherBase.SendAllAliveNotifications(Object state)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()
Thisd is fundamentally caused because OWIN has injected a Tracing writer that is NOT thread safe and sometimes (in this case, on a VM) there is a crash.
I have code to fix this, but am quite new to using github, so I may cause confusion and delay.
This is a general OWIN issue https://github.com/aspnet/AspNetKatana/issues/54