Arowin
Arowin

Reputation: 784

SignalR connection issues

I'm getting some issues with SignalR (1.1.2) trying to create a basic realtime chat setup and after spending about a week on it (including trawling through the SignalR source) I'm sort of at the end of what I can try...

I have (I think) a rather complicated SignalR setup consisting of:

Each of the sites includes the hub of itself and the other site, so each page can send messages to each site.

Looking into the Chrome inspector (in this example on the mobile site), the hubs are both loaded, the negotiate step for mobile is successful but the connect attempt fails after 3 seconds with the error:

EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.

which is of course our custom 500 error page after Microsoft.Owin.Host.SystemWeb has thrown:

The connection id is in the incorrect format.

Once this happens, most of the time this will then get into some sort of weird loop where it will continue to throw hundreds of these errors and send off lots of pings followed by a longPolling connect

The solution works perfectly well in my development environment (single IIS instance) but moving to the load balanced test environment is where I see the errors.

I don't know if there's anything else I can add that may help but I'm happy to add it.


I've added the following to the web.config files on both sites:

<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>

and

<add name="Access-Control-Allow-Origin" value="*"></add>
<add name="Access-Control-Allow-Headers" value="Content-Type" />

The global.asax files have:

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    RedisScaleoutConfiguration redisConfig = new RedisScaleoutConfiguration([redisIP], [port], String.Empty, "Name");
    redisConfig.Database = 9;
    GlobalHost.DependencyResolver.UseRedis(redisConfig);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    HubConfiguration hubConfig = new HubConfiguration();
    hubConfig.EnableCrossDomain = true;
    hubConfig.EnableDetailedErrors = true;
    RouteTable.Routes.MapHubs(hubConfig);

    <snip>
}

The JS code I have is along the lines of:

    function setUpSignalR() {
        //Set up the connections
        webConnection = $.hubConnection(pageInfo.webUrl);
        mobConnection = $.hubConnection(pageInfo.mobUrl);

        //Get the hubs for web and mobile
        webHub = webConnection.createHubProxies().messagingHub;
        mobHub = mobConnection.createHubProxies().messagingHub;

        //Hook up the call back functions
        <snip>

        //Now, start it up!
        mobConnection.logging = true;
        mobConnection.start().done(function() {
            mobHub.server.joinConversation(pageInfo.conversationGuid, "mobile").fail(function (error) { console.log('JoinConversation for mobile connection failed. Error: ' + error); });
            webConnection.start().done(function() {
                webHub.server.joinConversation(pageInfo.conversationGuid, "mobile").fail(function (error) { console.log('JoinConversation for web connection failed. Error: ' + error); });
            });
        });
    }

Upvotes: 1

Views: 3063

Answers (1)

Patrick Fletcher
Patrick Fletcher

Reputation: 284

From the SignalR troubleshooting document:

"The connection ID is in the incorrect format" or "The user identity cannot change during an active SignalR connection" error

This error may be seen if authentication is being used, and the client is logged out before the connection is stopped. The solution is to stop the SignalR connection before logging the client out.

Upvotes: 1

Related Questions