Bug 45335 - Null reference exceptions in System.Text.StringBuilder.Append, elsewhere
Summary: Null reference exceptions in System.Text.StringBuilder.Append, elsewhere
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2016-10-12 17:59 UTC by Andi McClure
Modified: 2016-10-31 22:13 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Andi McClure 2016-10-12 17:59:28 UTC
Various tests in make -w -C mono/tests -k test-wrench V=1 CI=1 are failing with an exception in StringBuilder.Append.

For some examples, see:

https://jenkins.mono-project.com/job/test-mono-mainline/label=osx-amd64/5077/parsed_console/log_content.html#WARNING1
https://jenkins.mono-project.com/job/test-mono-mainline/label=osx-amd64/5051/parsed_console/log_content.html#WARNING1

here the test seems to have failed in test-unhandled-exception-2-255-without-managed-handler, which appears to be a variation of unhandled-exception-2.exe with the TEST_UNHANDLED_EXCEPTION_HANDLER=1 flag.

Or see:

https://jenkins.mono-project.com/job/test-mono-mainline-linux/label=ubuntu-1404-i386/1031/parsed_console/log_content.html#WARNING1

here I think it failed in generic-virtual2.2.exe, but the stack is the same.

A stack looks like:

Unhandled Exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: value
  at System.Text.StringBuilder.Append (System.Char[] value, System.Int32 startIndex, System.Int32 charCount) [0x0005e] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Diagnostics.AsyncStreamReader.ReadBuffer (System.IAsyncResult ar) [0x00109] in <bd3e5df91d6f4033891a7298d03e6b21>:0 
  at System.IO.Stream+ReadWriteTask.InvokeAsyncCallback (System.Object completedTask) [0x00015] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.IO.Stream+ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke (System.Threading.Tasks.Task completingTask) [0x00060] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x000a0] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00045] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.FinishStageTwo () [0x000f8] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00049] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task& currentTaskSlot) [0x00079] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.ExecuteEntry (System.Boolean bPreventDoubleExecution) [0x0006f] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <d983932bcd7c4fc3894b81399e2dc136>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Value cannot be null.
Parameter name: value
  at System.Text.StringBuilder.Append (System.Char[] value, System.Int32 startIndex, System.Int32 charCount) [0x0005e] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Diagnostics.AsyncStreamReader.ReadBuffer (System.IAsyncResult ar) [0x00109] in <bd3e5df91d6f4033891a7298d03e6b21>:0 
  at System.IO.Stream+ReadWriteTask.InvokeAsyncCallback (System.Object completedTask) [0x00015] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.IO.Stream+ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke (System.Threading.Tasks.Task completingTask) [0x00060] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x000a0] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.FinishStageThree () [0x00045] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.FinishStageTwo () [0x000f8] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00049] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task& currentTaskSlot) [0x00079] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.ExecuteEntry (System.Boolean bPreventDoubleExecution) [0x0006f] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <d983932bcd7c4fc3894b81399e2dc136>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <d983932bcd7c4fc3894b81399e2dc136>:0 

This *might* be a general runtime problem with references going null; for example, in

https://jenkins.mono-project.com/job/test-mono-mainline-linux/label=ubuntu-1404-amd64/1017/parsed_console/log_content.html#WARNING1

we run what I think is the following test:

MONO_ENV_OPTIONS="--gc=sgen" MONO_GC_DEBUG="" MONO_GC_PARAMS="toggleref-test,major=marksweep-conc,minor=split" MONO_PATH=/mnt/jenkins/workspace/test-mono-mainline-linux/label/ubuntu-1404-i386/mcs/class/lib/net_4_x ../../runtime/mono-wrapper ./test-runner.exe --runtime ../../runtime/mono-wrapper --mono-path "/mnt/jenkins/workspace/test-mono-mainline-linux/label/ubuntu-1404-i386/mcs/class/lib/net_4_x" --config tests-config --runtime mono  --verbose --testsuite-name sgen-toggleref-tests-ms-conc-split --timeout 900 sgen-toggleref.exe

and get a stack like:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at System.Diagnostics.AsyncStreamReader.ReadBuffer (System.IAsyncResult ar) [0x000ed] in <6b82e0d0a4a84f4090439ac735eeba12>:0 
  at System.IO.Stream+ReadWriteTask.InvokeAsyncCallback (System.Object completedTask) [0x00015] in <7881416ebbbb4806a6f9be5adba554ed>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <7881416ebbbb4806a6f9be5adba554ed>:0 

But that might be an unrelated issue.
Comment 1 Andi McClure 2016-10-12 18:00:26 UTC
Marek, since there's a semi-consistent test failure here (the Mac AMD64 test-unhandled-exception-2-255-without-managed-handler test has occurred multiple times) and the immediate symptom occurs in the class library, can you look at this? If you find the class library is not at fault the runtime can look at it.
Comment 2 Marek Safar 2016-10-13 08:24:00 UTC
This is caused by Rodrigo's change https://github.com/mono/mono/commit/67d44f8ebfd7424846a08d8e00cc0091899f2ddd

We now explicitly close the stream even if it can still read data at same time. So we get null buffer as data length > 0.

I tried to follow Rodrigo's comment but I am not sure why output stream becomes inaccessible when it's wrapped by AsyncStreamReader and disposed there.
Comment 3 Rodrigo Kumpera 2016-10-13 22:38:09 UTC
After two rounds of fixing those dispose issues, I think they should be gone.
Comment 4 Rodrigo Kumpera 2016-10-31 22:13:17 UTC
Got not further reports on this.