Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Likely race condition in FileTraceWriter #1640

Open
paulbatum opened this issue Jun 29, 2017 · 3 comments
Open

Likely race condition in FileTraceWriter #1640

paulbatum opened this issue Jun 29, 2017 · 3 comments
Labels
Milestone

Comments

@paulbatum
Copy link
Member

A user on Azure Functions doing a high throughput event hubs scenario reported they often see an exception with the following trace:

System.ArgumentOutOfRangeException: Index and count must refer to a location within the buffer. Parameter name: chars at 
System.Text.EncoderNLS.GetBytes(Char[] chars, Int32 charIndex, Int32
 charCount, Byte[] bytes, Int32 byteIndex, Boolean flush) at 
System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at
System.IO.StreamWriter.Flush() at 
Microsoft.Azure.WebJobs.Host.CompositeTraceWriter.Flush() at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__14.MoveNext()

 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task
 task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__12.MoveNext()

(original report here)

From the trace it looks likely that the problem is unsynchronized access to a StreamWriter. Considering that FileTraceWriter has the only non-trivial implementation of TraceWriter.Flush, its the most likely source of the issue.

@paulbatum paulbatum added the bug label Jun 29, 2017
@fabiocav
Copy link
Member

We put a fix in place for this but in a couple of places. @brettsam this looks similar to the StringBuilder bug.

@brettsam
Copy link
Member

brettsam commented Jun 29, 2017

We had some similar races in the Core SDK, here:

It may come from FileTraceWriter, but it's not entirely clear:

  • I do see that this also has StringBuilder in the Flush path, but it's not in the stack for the error, which I would expect if it was the same bug. You also get a new StringBuilder with every call to Flush, unlike the above issues.
  • FileTraceWriter locks around its writing -- which is a call to File.AppendAllText. I wouldn't expect to see this come from that code.

@christopheranderson christopheranderson added this to the Triaged milestone Jul 7, 2017
@paulbatum paulbatum modified the milestones: Next, Triaged Aug 10, 2017
@AlexLvovsky
Copy link

Hi,
Are there any updates about this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants