Giter VIP home page Giter VIP logo

Comments (6)

darkl avatar darkl commented on August 21, 2024

Can you try 22.5.1-develop-39?

from wampsharp.

bigbearzhu avatar bigbearzhu commented on August 21, 2024

Thanks, have tied it locally. It seems AsyncLocalRpcOperation.InnerInvokeAsync is awaiting the task to finish internally and doing the cleanup when CallResult is called. However at that stage, in the outer call at WampCallee.InvocationPattern the invocationData may or may not have been added into the mInvocations. It depends on which of the two finish first: the inner invocation task finishes or WampCallee.InvocationPattern. So it may still leaks in this situation below:

Proxy interface:

    public interface IEchoService
    {
        [WampProcedure("com.test.echo")]
        Task<string> Echo(string message, CancellationToken cancellationToken);
    }

This will still leak:

    public class EchoService : IEchoService
    {
        public async Task<string> Echo(string message, CancellationToken cancellationToken)
        {
            return await Task.FromResult(message);
        }
    }

or

        public Task<string> Echo(string message, CancellationToken cancellationToken)
        {
            Thread.Sleep(100); // anything takes some time but synchronously.
            return Task.FromResult(message);
        }

image

But this will not:

    public class EchoService : IEchoService
    {
        public async Task<string> Echo(string message, CancellationToken cancellationToken)
        {
            await Task.Delay(10, cancellationToken); //note this delay here.
            return await Task.FromResult(message);
        }
    }

image

I am thinking if we could somehow create the CancellationTokenSourceInvocation in WampCallee.InvocationPattern and save it into mInvocations, then start the real invocation and pass in the CancellationTokenSourceInvocation to hook up the cancellation. Opinions?

from wampsharp.

bigbearzhu avatar bigbearzhu commented on August 21, 2024

After some try, I have got something like this on my fork branch. You can try run the LeakTestOnCancellableCalls and use dotMemory to see the leak is stopped now. Please see what you think about it.
image

from wampsharp.

darkl avatar darkl commented on August 21, 2024

@bigbearzhu thanks for working on this and for your contribution! Unfortunately, it seems like your solution breaks api (methods no longer return IWampCancellableInvocation). I fixed this issue differently by adding a property IsInvocationCompleted to IWampCancellableInvocation that checks whether the invocation has been completed, and in that case, I remove the invocation from the dictionary. Can you please try 22.5.1-develop-41 and let me know if the problem is solved?

Thanks!
Elad

from wampsharp.

bigbearzhu avatar bigbearzhu commented on August 21, 2024

Thanks @darkl and sorry for not replying for quite some time. I have checked the change, it seems it would harder to leak now with the IsInvocationCompleted check. However, because the inner invocation is running in different thread, so there is no guarantee that the inner invocation would always complete or not complete at right spot before the outer WampCallee doing its IsInvocationComplete check. I have created some dummy code with a test to show you one scenario that it could still leak. You can run CallerDealerTests.LeakTestOnCancellableCalls locally to see how it leaks.

This scenario is where inner invocation already passed calling WampCallee.CleanupInvocationData but somehow only completed after the outer code finished all its IsInvocationCompleted check.

DotMemory snapshot showing leak:
image

On our local fork, we have implemented a fix a little bit different as we need a fix urgently for this issue. Feel free to see if it is ok to cherry pick. The main idea of the fix is to move the registration code into the AsyncLocalRpcOperation so that it is guaranteed to add/clean registrations in right order. Also we rolled back the breaking api changes so that it still returns IWampCancellableInvocation.

from wampsharp.

darkl avatar darkl commented on August 21, 2024

Hi @bigbearzhu, I know it has been a long time. I attempted to resolve both of your issues in 23.3.1-develop-45. I would appreciate it if you could test it and tell me if the issues are gone, whenever you find the time.

Thanks,
Elad

from wampsharp.

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.