coreipc icon indicating copy to clipboard operation
coreipc copied to clipboard

.NET: fix UnobservedTaskException [ROBO-3622]

Open eduard-dumitru opened this issue 1 year ago • 0 comments

Scope

Here, we're deregistering and priming the observation of the Exception in RemoteCall's TaskCompletionSource should SendMessage throw. This is because it's imminent that the corresponding Task will become Faulted soon in cases of bidirectional pipes being closed abruptly (through Dispose from the ReceiveLoop). This could also happen in the case of cancellation/timeout when SendMessage also fails.

Briefly speaking, if you create a TCS, set its Exception, and let it become collected you get an UnobservedTaskException: image and this is what CoreIpc was doing.

Housekeeping

The master branch has a similar fix, I chose not to cherry-pick the fix because it involves significant changes (Task becoming ValueTask to name just the 1st).

Context

This was discovered through statically analyzing the reports generated in this Endurance run, more specifically in the 2024-03-10_18-38-35_Concurrent_Sessions.zip artifact, in Robot.log, at line 107874, where the unobserved task's exception's Data dictionary is printed. The Data dictionary was populated via a CoreIpc patch that captured the stack trace at the time of the RemoteCall, and registered it in the dictionary alongside the TaskCompletionSource. Then, when setting the exception on the it, the exception's Data property was filled with the stack information. The Robot was modified to print out this Data, and it became clear that the Robot doesn't cause the UnobservedTaskException by mishandling the Tasks.

eduard-dumitru avatar Mar 10 '24 23:03 eduard-dumitru