Trying to open a data stream form within a stream callback causes a deadlock

Using example "3.1.0 - Streaming - MarketPrice" and connecting via Eikon4

Replace the OnRefresh handler with the following code:

.OnRefresh((s,msg) =>
{
Console.WriteLine(msg);
using (IStream s_ = DeliveryFactory.CreateStream(new ItemStream.Params().Session(session).Name("CHF=")))
{   
s_.Open();   
Console.WriteLine("IT WORKED"); 
}
})

The program does not return from s_.Open() and will never print "IT WORKED".

Same result when trying to await an OpenAsync() call.

Best Answer

  • nick.zincone
    nick.zincone admin
    Answer ✓

    Hi @martin.grunwald,

    Yes, the above code will create a deadlock scenario. Try this:

    .OnRefresh(async (s, msg) =>
    {
    Console.WriteLine(msg);
    using (IStream s_ = DeliveryFactory.CreateStream(new ItemStream.Params().Session(session).Name("CHF="))
    {
    await s_.OpenAsync();
    Console.WriteLine("IT WORKED");
    }
    })