-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Concurrency issues around dispatch events and waiting for renders #118
Comments
Current thinking is that the issue is that subscribers to render events are in the processes of regenerating their DOM while the next render happens, since they are waiting on one thread and the rendere continues its work on another thread. Thus the Next thing to attempt is to change the notification system such that subscribers can return a Task when notified, that they should complete when they are done doing whatever work they need to do. Looking at the Renderer.cs code, it seems like it will await an uncompleted task before continuing with the next render - https://source.dot.net/#Microsoft.AspNetCore.Components/RenderTree/Renderer.cs,514 |
Pushed a new branch with semi complete attempt at new render event notification system. Needs more testing. Also, this cloud enable making tasks returned by e.g. |
Second update with a complete new notification pipeline, that looks like this: After a render is complete, but before
The core of the problem seems to have been:
To solution seems to be:
I am not convinced that the problem is gone. For example, if something inside a component under test, e.g. a public property, that the user is checking is changed in the same manner that can cause problems with the rendered markup, then that might suffer from the same problem. I did write a test very similar the markup ones that used to fail. It didn't fail during an overnight run, so there might be some mitigating factors in play. |
This blog describes the memory coherence problem Ive observed: http://benbowen.blog/post/cmmics_iii/ |
…#118 Squashed commit of the following: commit e8bde9b Author: Egil Hansen <[email protected]> Date: Fri May 8 11:31:40 2020 +0000 Fix to code doc commit 833e67d Author: Egil Hansen <[email protected]> Date: Fri May 8 11:29:22 2020 +0000 Code clean up commit 5f3b969 Author: Egil Hansen <[email protected]> Date: Fri May 8 11:12:13 2020 +0000 Removed unused using statements and reordered commit 2c809e1 Author: Egil Hansen <[email protected]> Date: Fri May 8 11:10:04 2020 +0000 Tweaks to code, simpler and general WaitForHelper class commit fbf0b2c Author: Egil Hansen <[email protected]> Date: Fri May 8 08:50:56 2020 +0000 Added additional test for testing changes to properties in components commit 0969f9d Author: Egil Hansen <[email protected]> Date: Thu May 7 17:48:25 2020 +0000 Removed test context waitfor functionality commit ff48f3d Author: Egil Hansen <[email protected]> Date: Thu May 7 17:11:01 2020 +0000 Added time stamp to log, and wrapped in try/catch, to handle scenarios where a message arrives after the test run is over. commit 46176c3 Author: Egil Hansen <[email protected]> Date: Thu May 7 10:53:40 2020 +0000 Moved to wait helper classes with locking and better protection for race conditions commit 98bfb08 Author: Egil Hansen <[email protected]> Date: Wed May 6 23:52:02 2020 +0000 Attempt at reworking notification of render events and provding more stable logic around waiting for functionality
Is there a branch with failing tests? Are those files already fixing the issue? Btw. I noticed in RenderedFragment lock (_lock)
{
return Volatile.Read(ref _markup);
} If locking is consistent (applied to all access), then Volatile.Read/Write is not necessary. |
These are basically the offending tests: https://www.github.com/egil/bunit/tree/dev/src%2Fbunit.core.tests%2FExtensions%2FWaitForHelpers%2FRenderedFragmentWaitForHelperExtensionsTest.cs And yes, the issue seems fixed (code on dev branch). I did an overnight run on my dual core laptop where these tests ran in a loop, and no errors occurred, compared to earlier where 1 of about 20 times one of the tests would fail. I'll try to remove the volatile read/writes then and just use the locks and see how it goes. See anything else I can improve? |
This is the powershell command I use to run it in a loop:
|
Just did a test without volatile, and it works as well. Can't remember exactly the setup before I added them, but the did help initially. Maybe I added the lock statement after. |
The following error shows up in 154 test runs out of about 3000:
Htmlizer.cs:line 44
, Assert.Debug (20 times)Htmlizer.cs:line 166
, Assert.Debug (14 times)Htmlizer.cs:line 59
, error InvalidOperationException : We didn't consume any input (33 times)Htmlizer.cs:line 93
, error InvalidOperationException : Invalid element frame type 'None' (28 times)RenderEventObservable.cs
is updated concurrently. Throws the following error message: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. (3 times)The text was updated successfully, but these errors were encountered: