SignalR Owin Host

441 views
Skip to first unread message

David Fowler

unread,
Dec 31, 2011, 6:45:04 PM12/31/11
to .NET HTTP Abstractions
Hey guys,

Over the past few days I've done some work to decouple SignalR from
ASP.NET (yay). Now I'm trying to implement an OWIN host and I'm having
some difficulty making it work under Kayak. The code for the host is
here:

https://github.com/SignalR/SignalR/blob/owin/SignalR.Owin/OwinHost.cs

Other related classes are here:

https://github.com/SignalR/SignalR/blob/owin/SignalR.Owin/

The code I'm using to test it is here:

https://gist.github.com/1545662

When I run the server and send requests from the signalr client, the
continuation for reading the request body is never called. Louis
( pointed out that it might have something to do with the Owin host
(in this case Kayak) might be using the single threaded event loop
scheduler and my code isn't friendly for that (https://twitter.com/#!/
loudej/status/153249927768711168).

How do I make this work?

Louis DeJardin

unread,
Jan 1, 2012, 4:22:46 AM1/1/12
to net-http-a...@googlegroups.com
That's very peculiar.

I pushed an update of Gate bits for v0.2.0, and also forked SignalR to update the Gate references and code in the SignalR owin branch.

https://github.com/loudej/signalr/tree/owin

One thing I noticed - it seems to be able to get past the POST to "/negotiate" if you comment out the .RescheduleCallbacks() middleware. Not sure why that is - but that will get you to the next GET to "/connect" which doesn't return a result.

For that - even with the reschedule middleware commented out - the eventKey "SignalrKayakGateDemo.Raw" in the InProcessSignalBus seems to arrive at the OnSignaled method before the AddHandler method. It looks like Kayak has a custom TaskScheduler in effect? Maybe a subtle race condition that the custom scheduler will repro consistently?

I'll look further - feel free to clone the loudej/signalr to checkout owin branch.

-Lou

Benjamin van der Veen

unread,
Jan 1, 2012, 5:08:30 PM1/1/12
to net-http-a...@googlegroups.com, davi...@gmail.com
On Sat, Dec 31, 2011 at 3:45 PM, David Fowler <davi...@gmail.com> wrote:
> https://github.com/SignalR/SignalR/blob/owin/SignalR.Owin/OwinHost.cs

If your intention is to buffer the request body into a string, you
should be appending the `text` variable, rather than assigning it,
since that callback could be invoked multiple times. (You might
re-consider buffering it into a string if you ever want to handle
binary data…)

> When I run the server and send requests from the signalr client, the
> continuation for reading the request body is never called.

Sorry, which callback exactly isn't being invoked as expected?

David Fowler

unread,
Jan 1, 2012, 5:41:53 PM1/1/12
to .NET HTTP Abstractions
Thanks for that, i'll change it once I get something basic working. If
you look at the host code, there's a ParseBodyAsync method:

private static Task<string> ParseBodyAsync(IDictionary<string, object>
environment)
{
var requestBodyDelegate = GetRequestBodyDelegate(environment);

var tcs = new TaskCompletionSource<string>();
if (requestBodyDelegate == null)
{
tcs.SetResult(null);
return tcs.Task;
}

string text = null;

requestBodyDelegate.Invoke((data, continuation) =>
{
// TODO: Check the continuation and read async if it isn't
null
text = Encoding.UTF8.GetString(data.Array, data.Offset,
data.Count);
return false;
},
tcs.SetException,
() => tcs.SetResult(text));

return tcs.Task;
}

None of the callbacks seemed to be called so it's just hanging.


On Jan 1, 2:08 pm, Benjamin van der Veen <b...@bvanderveen.com> wrote:

Benjamin van der Veen

unread,
Jan 2, 2012, 12:11:14 AM1/2/12
to net-http-a...@googlegroups.com
On Jan 1, 2012, at 2:41 PM, David Fowler <davi...@gmail.com> wrote:

> None of the callbacks seemed to be called so it's just hanging.

That's strange. Hmm...The request body delegate in non-null and your client is posting non-zero-length data?

David Fowler

unread,
Jan 2, 2012, 9:08:11 AM1/2/12
to .NET HTTP Abstractions
If the content length is 0 the callbacks will never be called?

On Jan 1, 9:11 pm, Benjamin van der Veen <b...@bvanderveen.com> wrote:

Louis DeJardin

unread,
Jan 2, 2012, 2:36:54 PM1/2/12
to David Fowler, .NET HTTP Abstractions
It there's a non-null body delegate you should get one callback to
error or complete, at a minimum.

--
Louis - sent from mobile
From: David Fowler
Sent: 1/2/2012 6:08 AM
To: .NET HTTP Abstractions
Subject: Re: SignalR Owin Host

David Fowler

unread,
Jan 2, 2012, 2:38:58 PM1/2/12
to .NET HTTP Abstractions
Yea, it's just not working.

Benjamin van der Veen

unread,
Jan 2, 2012, 3:07:41 PM1/2/12
to net-http-a...@googlegroups.com, .NET HTTP Abstractions
Try compiling Kayak from the latest master.

Louis DeJardin

unread,
Jan 2, 2012, 6:13:23 PM1/2/12
to Benjamin van der Veen, net-http-a...@googlegroups.com
Yeah, I'll try running the whole stack from source under debugger...
SignalR's a great test-case, really. Very extreme requirements.

--
Louis - sent from mobile

Scott Koon

unread,
Jan 6, 2012, 2:25:32 PM1/6/12
to net-http-a...@googlegroups.com
I think it's great that David took the time and effort to get this running under Kayak and OWIN/Gate. Always good to get folks "road testing" the spec.  

Louis DeJardin

unread,
Jan 6, 2012, 2:47:55 PM1/6/12
to net-http-a...@googlegroups.com

Absolutely!

 

Say, David, are you unblocked by what was pushed up, or are you still waiting for something?

David Fowler

unread,
Jan 7, 2012, 11:32:42 AM1/7/12
to .NET HTTP Abstractions
Your fork helps alot, thanks Louis. I'll see what I can do from there.

On Jan 6, 11:47 am, Louis DeJardin <lodej...@microsoft.com> wrote:
> Absolutely!
>
> Say, David, are you unblocked by what was pushed up, or are you still waiting for something?
>
> From: net-http-a...@googlegroups.com [mailto:net-http-a...@googlegroups.com] On Behalf Of Scott Koon
> Sent: Friday, January 06, 2012 11:26 AM
> To: net-http-a...@googlegroups.com
> Subject: Re: SignalR Owin Host
>
> I think it's great that David took the time and effort to get this running under Kayak and OWIN/Gate. Always good to get folks "road testing" the spec.

Louis DeJardin

unread,
Jan 9, 2012, 4:44:48 PM1/9/12
to .NET HTTP Abstractions
Sounds good. Something I noticed is you may need an End() on your
IResponse abstraction. It was pretty difficult to know which data
writes were intended to end the http response, and which were intended
to flush to the wire but remain writable.
Reply all
Reply to author
Forward
0 new messages