question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConfigureAwait(this) shouldn't run the continuation if the owner is destroyed.

See original GitHub issue

Love your library!

Say you have some code like this:

async void Start()
{
    await Await.Seconds(5).ConfigureAwait(this);
    transform.position = new Vector3(1, 2, 3);  // will crash if object was destroyed
}

Currently, if the GameObject or Component is destroyed, the continuation runs immediately, which would cause a crash. I think it would be more intuitive if the continuation were cancelled instead. This is probably what the user wants most of the time and is consistent with how coroutines work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
muckSpongecommented, Aug 12, 2019

Yes, I’m unable to come up with a logical situation where someone would tie it to an owner that doesn’t await on it or at least have some dependencies with the awaiting object so probably no point complicating things with an exception or exception option.

I’ve resolved the potential managed memory leak in 5430f351c9a06377d61018a946dcbb24c55418b4.

0reactions
mikehofmcommented, Aug 11, 2019

So my instinct is that once an object is destroyed, you rarely want to continue with the continuation. Your code is probably going to use some member of the owning object and crash; if the code had no dependencies on that object, it probably wouldn’t be in the object to begin with (or at least, you wouldn’t have called ConfigureAwait(this)). Of course, it’s hard to predict what use cases people might have.

I think the static Exception variable is safe here, but I don’t know enough about async/await to be confident.

One unrelated thing I noticed: in ContinuationProcessor, you don’t clean up the completed IContinuations. This could prevent any references held by the IContinuation from being garbage collected. You could probably add Array.Clear(currentQueue, 0, count); at the end of Process().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why ConfigureAwait(false) does not work while Task.Run() ...
ConfigureAwait(false) can only prevent deadlocks if it is used by every await in the transitive closure of that method and all methods it...
Read more >
[Proposal] Forcing ConfigureAwait(false) on assembly level
ConfigureAwait(false) has no effect on completed tasks. If a task is already completed, then the execution continues on the same thread (that ...
Read more >
Why I no longer use ConfigureAwait(false)
I've personally chosen to avoid ConfigureAwait(false) where possible, and control the execution context explicitly where it makes sense.
Read more >
ConfigureAwait FAQ - .NET Blog
ConfigureAwait (false) involves a task that's already completed by the time it's awaited (which is actually incredibly common), then the ...
Read more >
When to use ConfigureAwait(false) : r/dotnet
What ConfigureAwait(false) does is prevent the current execution context from being captured and passed to the continuation. If your method ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found