Giter VIP home page Giter VIP logo

Comments (6)

StephenCleary avatar StephenCleary commented on May 21, 2024

Yes, I think your fix is appropriate. I do have to double-check some related semantics and make sure.

On a side note, the .NET Core version of AsyncEx primitives do always use asynchronous continuations.

from asyncex.

fry avatar fry commented on May 21, 2024

Hi! Is there an update on this? I am having that issue I believe (and the same StackOverflow with stack trace from windbg). Or perhaps a work-around? Sorry, I couldn't quite figure it out from the linked SO post.

from asyncex.

StephenCleary avatar StephenCleary commented on May 21, 2024

@fry: The new version of the async coordination primitives is available in a prerelease version.

There have been some (minor) API changes, but most upgrades should go quite smoothly.

from asyncex.

IanYates avatar IanYates commented on May 21, 2024

I ran into this in my codebase a few times. I haven't switched to the new API yet but will do so in a few weeks when I can have things broken for a few days (testing for this sort of thing is hard as it is tricky to reproduce).

In my code I had a whole bunch of repositories wait on a single shared async lock on startup - it was to allow initialisation to happen exactly once (but not too soon). Those repositories could have 100 or so clients waiting to make their first request. Rather than have so many waiters on the one async lock, I added another async lock and a flag to each repository so the queue of waiters was spread amongst more locks. That solved the problem for me.
It was one of those weird things though where I quite happily had N repositories with M initial requests each, but as soon as I bumped M up by a few and then added my N+1th repository I consistently got stack overflows.

At one stage I experimented with awaiting Task.Yield() too. I'm not entirely sure that helped as I'm not familiar enough with the internals of how that might interact with the call stack and continuations.

Note that I'm not really making any use of ConfigureAwait() anywhere. That might have an effect too as far as call stack depth is concerned.

from asyncex.

glen-nicol avatar glen-nicol commented on May 21, 2024

I am having similar trouble running 3.0.1. I have the following wrapper class around AsyncMonitor

public class EasyAsyncMonitor
{
    private AsyncMonitor _monitor = new AsyncMonitor();

    public Task WaitAsync(CancellationToken token = default(CancellationToken))
    {
        return EnterMonitorAndDo(() =>
        {
            return _monitor.WaitAsync();
        }, token);
    }

    public Task Pulse(CancellationToken token = default(CancellationToken))
    {
        return EnterMonitorAndDo(() => 
        {
            _monitor.Pulse();
        }, token);
    }

    public Task PulseAll(CancellationToken token = default(CancellationToken))
    {
        return EnterMonitorAndDo(() => 
        {
            _monitor.PulseAll();
        }, token);
    }

    private async Task EnterMonitorAndDo(Func<Task> doThis, CancellationToken token)
    {
        using(await _monitor.EnterAsync(token))
        {
            await doThis().DetachContext(); //Overflow occurs here
        }
    }

    private async Task EnterMonitorAndDo(Action doThis, CancellationToken token)
    {
        using(await _monitor.EnterAsync(token))
        {
            doThis();
        }
    }
}

And DetachContext is defined as

public static ConfiguredTaskAwaitable DetachContext(this Task t)
{
    return t.ConfigureAwait(false);
}

Occasionally I will get a stackoverflow exception thrown from the line indicated above with the comment. The stack trace is unavailable but is visible in Visual studio debugging. It is full of that single line and then [Resuming Async Method] and [External code] entries between them.

Could this be related or is it incorrect usage of the Monitor?

from asyncex.

StephenCleary avatar StephenCleary commented on May 21, 2024

Should be fixed in 4.0.0-pre.

from asyncex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.