hyperledger-archives / aries-mobile-agent-xamarin

Apache License 2.0
39 stars 31 forks source link

Mediator Stuck and isn't Updating (sending/receiving messages to mobile agent) #33

Closed x0axz closed 3 years ago

x0axz commented 3 years ago

2 Months ago, updated the Hyperledger.Aries.Routing.Edge to 1.6.1 from 1.4.0 and last week I noticed that we were getting an error in Presentation Proof, used the older version of agents and were still getting that same error. Noticed, that mediator got stuck and wasn't updating (after every 10 seconds, it route messages to mobile agent from issuer/verifier agent).

Now, using 1.4.0 again and Connections are most of time stuck in Negotiating, Credentials in Requested state e.t.c, and all these issues because of the reason that Mediator stuck and isn't routing messages.

I only noticed this error in mediator logs few times.

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected end of request content.
   at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ContentLengthMessageBody.ReadAsyncInternal(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)
   at System.IO.StreamReader.ReadBufferAsync(CancellationToken cancellationToken)
   at System.IO.StreamReader.ReadToEndAsyncInternal()
   at Hyperledger.Aries.AspNetCore.AgentMiddleware.Invoke(HttpContext aHttpContext, IAgentProvider aAgentProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
x0axz commented 3 years ago

@horationunez what I noticed is that, when Issuer sends a credential proposal to mobile or issue credentials to mobile OR verifier asks from mobile to verify the credentials by presenting proof, when Mediator Received the Payload from Issuer/Verifier, mobile stops sending an Agent Message (which mobile sends to mediator after 3 second time interval) to check if mediator has any message for it.

Sometimes after many minutes later, mediator starts receiving messages or sometime after restarting the mediator, it start receiving messages.

I never faced this kind of behavior before, I haven't change anything in the code. Is there any thing maybe I'm doing wrong?

horationunez commented 3 years ago

You should have a lot of control when it comes to check for new Messages in the Mediator. In this line we explicitly request to check for new messages.

Are you also using the latest possible Mediator package?

If you keep having problems I'm happy to jump on a call to help you debug the problem later this week.

You can setup a time in this link: https://calendly.com/merthin/ariesmax

x0axz commented 3 years ago

Thanks for response, actually we compared the code with older version and didn't found any much differences. Downgrade the packages, still we see the delays.

Thank you for taking the time, could you give us time in tomorrow or the day after tomorrow?

horationunez commented 3 years ago

No worries. The day after tomorrow sounds good +1

x0axz commented 3 years ago

Thanks. Add a slot in calendar.

x0axz commented 3 years ago

Hi @horationunez , I downgrade the Hyperledger.Aries.Routing.Edge to 1.2.9 in Mobile app, which is same as in Mediator, and the delay isn't too long now.

I didn't understand why downgrading the aries packages in mobile and mediator, take less time to Establish Connection, Issue Credentials and Verify Credentials, compared to latest aries packages.

x0axz commented 3 years ago

Solved the Problem!!!

In App.xml.cs, there is a function OnStart(), where the mediator timer is set to enabled. What I was doing wrong was, I put the statement (timer.Enabled = true;) inside the else statement, which is wrong. It should be outside of curly brackets because It has to be enabled no matter which condition become true.

protected override async void OnStart()
{
    if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
    {    }
    else
    {    }

    timer.Enabled = true;
}