microsoft / RTVS

R Tools for Visual Studio.
MIT License
390 stars 111 forks source link

OperationCancelledException in OWIN Web service #4327

Open yakimovim opened 6 years ago

yakimovim commented 6 years ago

I'm trying to use Microsoft.R.Host.Client.API inside Owin Web service. The code of controller is:

public class RlangController : ApiController
{
    [Route("data/{dataId}/execute-r-query")]
    [HttpPost]
    [ResponseType(typeof(ResponseModel))]
    public async Task<IHttpActionResult> RawQueryAction(long dataId
        , [FromBody]RequestModel requestModel)
    {
        try
        {
            var session = RHostSession.Create("AAA", @"c:\Program Files\R\R-3.5.1\");
            await session.StartHostAsync(new RHostSessionCallback());

            ....

At the call of session.StartHostAsync I get OperationCancelledException:

   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.IO.Pipes.NamedPipeServerStream.EndWaitForConnection(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.R.Host.Client.Host.LocalBrokerClient.<ConnectToBrokerWorker>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Host.LocalBrokerClient.<EnsureBrokerStartedAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Host.LocalBrokerClient.<ConnectAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Session.RSession.<StartHostAsyncBackground>d__111.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Session.RSession.<StartHostAsync>d__110.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at WebService.Controllers.RlangController.<RawQueryAction>d__0.MoveNext() in C:\dev\service\WebService\Controllers\RLangController.cs:line 53

At the same time, if I use ASP.NET MVC application (without Owin) the same code works fine.

Do you have any idea about the reason of such behaviour?

Thank you!

apumex commented 6 years ago

I'm trying to use Microsoft.R.Host.Client.API inside Owin Web service. The code of controller is:

public class RlangController : ApiController
{
    [Route("data/{dataId}/execute-r-query")]
    [HttpPost]
    [ResponseType(typeof(ResponseModel))]
    public async Task<IHttpActionResult> RawQueryAction(long dataId
        , [FromBody]RequestModel requestModel)
    {
        try
        {
            var session = RHostSession.Create("AAA", @"c:\Program Files\R\R-3.5.1\");
            await session.StartHostAsync(new RHostSessionCallback());

            ....

At the call of session.StartHostAsync I get OperationCancelledException:

   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.IO.Pipes.NamedPipeServerStream.EndWaitForConnection(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.R.Host.Client.Host.LocalBrokerClient.<ConnectToBrokerWorker>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Host.LocalBrokerClient.<EnsureBrokerStartedAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Host.LocalBrokerClient.<ConnectAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Session.RSession.<StartHostAsyncBackground>d__111.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.R.Host.Client.Session.RSession.<StartHostAsync>d__110.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at WebService.Controllers.RlangController.<RawQueryAction>d__0.MoveNext() in C:\dev\service\WebService\Controllers\RLangController.cs:line 53

At the same time, if I use ASP.NET MVC application (without Owin) the same code works fine.

Do you have any idea about the reason of such behaviour?

Thank you!

Any luck with this, I also facing the same issue

yakimovim commented 6 years ago

No, still no changes.