Skip to content

Using disposable objects in Orchestration functions #1225

@MarcinJuraszek

Description

@MarcinJuraszek

Is there any guidance on how to correctly use objects that implement IDisposable in Orchestration functions?

Let's consider something like this:

using (IActivityScope scope = _activityScopeFactory.CreateScope())
{
    await context.CallActivityAsync("TestActivity1");
    await context.CallActivityAsync("TestActivity2");

    // (...) etc.
}

Unless we're doing something wrong, the current behavior we're observing is that the scope object will be created multiple times, every time the orchestration is re-run to be replayed when the various activity complete. However, the Dispose on said scope only ever gets called once, as the orchestration completes?

Is there a way to somehow get it to always run?

We're doing this for logging and instrumentation, so there's no risk of leaking expensive stuff, but it's still quite annoying because the data we gather with this flow is just not correct. We'd love to get any insight on how to do it the right way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions