0

We had https://www.nuget.org/packages/Microsoft.AspNet.WebApi.SelfHost/ Web Api service and it works fine. Then we migrated to https://www.nuget.org/packages/Microsoft.AspNet.WebApi.OwinSelfHost/ and we have a problem. We deploy service to server and after 40-60 min we get error and service doesn't response and we couldn't stop it. Then we kill process and start service and it works fine about next 40-60 min. As I understand, logentries appender's thread or queque doesn't response, because we see logs in file, but don't in logentries

<appender name="LeAppender" type="log4net.Appender.LogentriesAppender, LogentriesLog4net">
<Debug value="true" />
<HttpPut value="false" />
<Ssl value="false" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="|%level%| %m" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="LeAppender" />
</root>

Error:

XXXX-XX-XX XX-XX-XX,XXX [Logentries Log Appender] FATAL Topshelf.Runtime.Windows.WindowsServiceHost The service threw an unhandled exception System.IndexOutOfRangeException: 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.
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.TraceInternal.WriteLine(String message)
at LogentriesCore.Net.AsyncLogger.WriteDebugMessages(String message)
at LogentriesCore.Net.AsyncLogger.Run()
at System.Threading.ThreadHelper.ThreadStart_Context(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.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

When I enabled debug mode, I got more information. Is it problem with appender or my application? How can I get more information?

log4net:ERROR [LogentriesAppender] ErrorCode: GenericFailure. Failed in DoAppend
LE: Write complete, flush
LE: Flush complete
LE: Await queue data
System.IndexOutOfRangeException: 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.
   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.TraceInternal.WriteLine(String message)
   at LogentriesCore.Net.AsyncLogger.WriteDebugMessages(String message)
   at LogentriesCore.Net.AsyncLogger.AddLine(String line)
   at log4net.Appender.LogentriesAppender.Append(LoggingEvent loggingEvent)
   at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
1

2 Answers 2

0

The stack trace you've posted shows the error occurs in AsyncLogger.WriteDebugMessages() - the source shows that this method is used for recording internal debugging messages, so setting <Debug value="false" /> in the config should stop this happening.

You should also raise an issue on the library with a repro, so it can be fixed.

0

Problem with internal debug https://github.com/rapid7/le_dotnet/blob/1b2443a581a6f1a877bf90f472a44eaf5ffe0fa5/src/LogentriesCore/AsyncLogger.cs#L596

When we changed debug to false appender works.

Oleg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.