roslyn: StackOverflow in IncrementallyParseTreeAsync
From @kumpera:
https://bugzilla.xamarin.com/show_bug.cgi?id=55597
- checkout mono
- open mcs/class/corlib/corlib-net_4_x.csproj
- open string.cs
- scroll to the bottom and wait for Roslyn analysis to show up - tons of yellow stuff will light up on the right side
- start typing on the last line
After some typing (20ish words) I get a stack overflow followed by a hard crash on this stack:
(lldb) bt 40
* thread #114, name = 'Threadpool worker', stop reason = EXC_BAD_ACCESS (code=2, address=0x7000042c0ff8)
* frame #0: Mono`System.Environment:get_CurrentManagedThreadId () at Environment.cs:163
frame #1: 0x0000000147e77851 Mono`Roslyn.Utilities.NonReentrantLock:get_IsOwnedByMe () + 33
frame #2: 0x0000000147e773bf Mono`Roslyn.Utilities.NonReentrantLock:Wait (System.Threading.CancellationToken) + 111
frame #3: 0x000000014801bdeb Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:TakeLock (System.Threading.CancellationToken) + 107
frame #4: 0x000000014801b6e8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:GetValueAsync (System.Threading.CancellationToken) + 728
frame #5: 0x000000014b7a189c Mono`Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13:MoveNext () + 1020
frame #6: Mono`System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Microsoft.CodeAnalysis.TreeAndVersion>:Start<Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13> (Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13&) at AsyncMethodBuilder.cs:471
frame #7: Mono`Microsoft.CodeAnalysis.DocumentState:IncrementallyParseTreeAsync (Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TreeAndVersion>,Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TextAndVersion>,System.Threading.CancellationToken) at TextFileUtility.cs:280
frame #8: 0x000000014b79f5ca Mono`Microsoft.CodeAnalysis.DocumentState/<>c__DisplayClass12_0:<CreateLazyIncrementallyParsedTree>b__0 (System.Threading.CancellationToken) + 42
frame #9: 0x000000014801f2c8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:StartAsynchronousComputation (Roslyn.Utilities.AsyncLazy`1/AsynchronousComputationToStart<T_REF>,Roslyn.Utilities.AsyncLazy`1/Request<T_REF>,System.Threading.CancellationToken) + 344
frame #10: 0x000000014801b99f Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:GetValueAsync (System.Threading.CancellationToken) + 1423
frame #11: 0x000000014b7a189c Mono`Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13:MoveNext () + 1020
frame #12: Mono`System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Microsoft.CodeAnalysis.TreeAndVersion>:Start<Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13> (Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13&) at AsyncMethodBuilder.cs:471
frame #13: Mono`Microsoft.CodeAnalysis.DocumentState:IncrementallyParseTreeAsync (Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TreeAndVersion>,Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TextAndVersion>,System.Threading.CancellationToken) at TextFileUtility.cs:280
frame #14: 0x000000014b79f5ca Mono`Microsoft.CodeAnalysis.DocumentState/<>c__DisplayClass12_0:<CreateLazyIncrementallyParsedTree>b__0 (System.Threading.CancellationToken) + 42
frame #15: 0x000000014801f2c8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:StartAsynchronousComputation (Roslyn.Utilities.AsyncLazy`1/AsynchronousComputationToStart<T_REF>,Roslyn.Utilities.AsyncLazy`1/Request<T_REF>,System.Threading.CancellationToken) + 344
frame #16: 0x000000014801b99f Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:GetValueAsync (System.Threading.CancellationToken) + 1423
frame #17: 0x000000014b7a189c Mono`Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13:MoveNext () + 1020
frame #18: Mono`System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Microsoft.CodeAnalysis.TreeAndVersion>:Start<Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13> (Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13&) at AsyncMethodBuilder.cs:471
frame #19: Mono`Microsoft.CodeAnalysis.DocumentState:IncrementallyParseTreeAsync (Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TreeAndVersion>,Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TextAndVersion>,System.Threading.CancellationToken) at TextFileUtility.cs:280
frame #20: 0x000000014b79f5ca Mono`Microsoft.CodeAnalysis.DocumentState/<>c__DisplayClass12_0:<CreateLazyIncrementallyParsedTree>b__0 (System.Threading.CancellationToken) + 42
frame #21: 0x000000014801f2c8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:StartAsynchronousComputation (Roslyn.Utilities.AsyncLazy`1/AsynchronousComputationToStart<T_REF>,Roslyn.Utilities.AsyncLazy`1/Request<T_REF>,System.Threading.CancellationToken) + 344
frame #22: 0x000000014801b99f Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:GetValueAsync (System.Threading.CancellationToken) + 1423
frame #23: 0x000000014b7a189c Mono`Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13:MoveNext () + 1020
frame #24: Mono`System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Microsoft.CodeAnalysis.TreeAndVersion>:Start<Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13> (Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13&) at AsyncMethodBuilder.cs:471
frame #25: Mono`Microsoft.CodeAnalysis.DocumentState:IncrementallyParseTreeAsync (Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TreeAndVersion>,Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TextAndVersion>,System.Threading.CancellationToken) at TextFileUtility.cs:280
frame #26: 0x000000014b79f5ca Mono`Microsoft.CodeAnalysis.DocumentState/<>c__DisplayClass12_0:<CreateLazyIncrementallyParsedTree>b__0 (System.Threading.CancellationToken) + 42
frame #27: 0x000000014801f2c8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:StartAsynchronousComputation (Roslyn.Utilities.AsyncLazy`1/AsynchronousComputationToStart<T_REF>,Roslyn.Utilities.AsyncLazy`1/Request<T_REF>,System.Threading.CancellationToken) + 344
frame #28: 0x000000014801b99f Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:GetValueAsync (System.Threading.CancellationToken) + 1423
frame #29: 0x000000014b7a189c Mono`Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13:MoveNext () + 1020
frame #30: Mono`System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Microsoft.CodeAnalysis.TreeAndVersion>:Start<Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13> (Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13&) at AsyncMethodBuilder.cs:471
frame #31: Mono`Microsoft.CodeAnalysis.DocumentState:IncrementallyParseTreeAsync (Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TreeAndVersion>,Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TextAndVersion>,System.Threading.CancellationToken) at TextFileUtility.cs:280
frame #32: 0x000000014b79f5ca Mono`Microsoft.CodeAnalysis.DocumentState/<>c__DisplayClass12_0:<CreateLazyIncrementallyParsedTree>b__0 (System.Threading.CancellationToken) + 42
frame #33: 0x000000014801f2c8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:StartAsynchronousComputation (Roslyn.Utilities.AsyncLazy`1/AsynchronousComputationToStart<T_REF>,Roslyn.Utilities.AsyncLazy`1/Request<T_REF>,System.Threading.CancellationToken) + 344
frame #34: 0x000000014801b99f Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:GetValueAsync (System.Threading.CancellationToken) + 1423
frame #35: 0x000000014b7a189c Mono`Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13:MoveNext () + 1020
frame #36: Mono`System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Microsoft.CodeAnalysis.TreeAndVersion>:Start<Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13> (Microsoft.CodeAnalysis.DocumentState/<IncrementallyParseTreeAsync>d__13&) at AsyncMethodBuilder.cs:471
frame #37: Mono`Microsoft.CodeAnalysis.DocumentState:IncrementallyParseTreeAsync (Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TreeAndVersion>,Roslyn.Utilities.ValueSource`1<Microsoft.CodeAnalysis.TextAndVersion>,System.Threading.CancellationToken) at TextFileUtility.cs:280
frame #38: 0x000000014b79f5ca Mono`Microsoft.CodeAnalysis.DocumentState/<>c__DisplayClass12_0:<CreateLazyIncrementallyParsedTree>b__0 (System.Threading.CancellationToken) + 42
frame #39: 0x000000014801f2c8 Mono`Roslyn.Utilities.AsyncLazy`1<T_REF>:StartAsynchronousComputation (Roslyn.Utilities.AsyncLazy`1/AsynchronousComputationToStart<T_REF>,Roslyn.Utilities.AsyncLazy`1/Request<T_REF>,System.Threading.CancellationToken) + 344
(lldb)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (19 by maintainers)
This has happened before in a typing-like scenario (lots of small changes) where nothing requests the tree for a long period. Each change builds up a chain of pending incremental parses. Eventually, when the request does come, the chain is too long and there is a stack overflow. This generally doesn’t happen in VS typing, since the background parser is always requesting the tree.
If this is the cause, then I already have a PR to fix it: #13442