Skip to content

Asynchronous execution of DisposeContext() can cause hardware race condition #572

@jonnew

Description

@jonnew

When a workflow is stopped, the readFrames Task withing ContextTask is cancelled. This in turn ends the acquisition Task, which is linked to the lifetime of readFrames via a WhenAll. The end of the acquisition task indicates the end of acqusition and thus that the underlying oni context can be destroyed. This is performed with an asynchronous continuation:

acquisition.ContinueWith(_ => DisposeContext());

If another ContextTask is created, and its constructor called, when this continuation is executing, then ctx = new oni.Context(contextDriver, contextIndex); can be called against hardware that is not completely freed by the original ContextTask. This can result in an "Attempt to trigger and already triggered operation" exception.

Image

To prevent this, DisposeContext() must complete execution before the ContextTask.Dispose() returns. This can done using Wait() or GetAwaiter().GetResult() on the continuation task. The later will not mangle an exception that is thrown from DisposeContext().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions