locked
Session/DurableSession (CreateSession and AttachSession) blocks and does not return RRS feed

  • Question

  • Hello,

    I am running into an issue where if I call CreateSession or AttachSession in a thread created by TaskFactory.StartNew using the LimitedConcurrencyLevelTaskScheduler (https://msdn.microsoft.com/en-us/library/ee789351(v=vs.100).aspx), it will block and not return. This doesn't occur if the number of threads created are less than the number of processors on the system or the application is running on the head node. I was hoping for some suggestions to figure out why this is happening.

    Thanks!

    Thursday, June 8, 2017 6:24 PM

All replies

  • Hi llam10,

    What's the version of SOA Session API (Microsoft.Hpc.Scheduler.Session.dll) and HPC Pack are you using? What's the targeted .net framework for the client code? Could you paste the sample code that hangs for reference?

    Regards,

    Yutong Sun

    Tuesday, June 13, 2017 9:33 AM
  • Microsoft.Hpc.Scheduler.Session.dll Version 5.0.5826.0

    HPC Pack 2016

    .Net Framework 4.6.1

    I was able to resolve the issue by calling CreateSession in a new Task. But the idea is that I have a ProducerConsumerQueue (internally it is a BlockingCollection), that creates new consumer tasks using the TaskFactory with the LimitedConcurrencyLevelTaskScheduler. The producer will queue a WorkItem that contains a TaskCompletionSource and a Func (this is where CreateSession is called) to execute. The consumer tasks will then dequeue that WorkItem and call TaskCompletionSource.SetResult(Func) and it will block in the Func.

    Wednesday, June 14, 2017 2:10 PM
  • Hi llam10,

    CreateSession is blocking version of an async api CreateSessionAsync, which means it may spawn other threads to accomplish its work. If number of threads started for running CreateSession hits the thread limit of LimitedConcurrencyLevelTaskScheduler, async task which needs a new thread to complete will never get scheduled. Then you will see CreateSession blocking.

    Thanks,
    Zihao


    Friday, June 16, 2017 1:45 AM
  • Hi llam10,

    To be more specific, CreateSession would call HttpClient.GetAsync which is an async call that resumes on the captured LimitedConcurrencyLevelTaskScheduler. If the number of sync CreateSession hit the thread limit, then deadlock happens. If you create a new Task for CreateSession, it would start in a new context, so no thread limit hit, which may defect the purpose though. I would suggest to use the CreateSessionAsync api as Zihao mentioned, and use factory.StartNew(async () => await Session.CreateSessionAsync...) not to block the Task threads in the LimitedConcurrencyLevelTaskScheduler.

    Regards,

    Yutong Sun

    Friday, June 16, 2017 6:41 AM