DSC00002

SignalR: The ConnectionId is in the incorrect format – an alternative cause.

Recently, on an application using SignalR, we found that we were getting many System.InvalidOperationException: The ConnectionId is in the incorrect format exceptions (sometimes 10 per second) from the SignalR hubs in the site.

While there is plenty of discussion on the causes of this error in SignalR documentation and on Q&A sites, they mostly discuss problems with changing levels of authentication (SignalR defines a new connection when the auth level, or authorized user, changes). In this case though this wasn’t relevant. The volume implied that this was unlikely to be the cause, and in anycase, the site was already written to cope with these changes on login.

The cause turned out to be search engine crawler services.

The culprit – search engine crawlers

On inspecting the logs from the site, and logged exception/context information, it was clear that the site was being visited by the crawlers for the various search engines, and that these were not interacting well with SignalR.

Modern crawlers, in addition to indexing static html, now investigate javascript within the site for possible sources of content to be indexed. When they hit the SignalR stuff things start to go wrong for two primary reasons:

  • The crawler sends the wrong content to the SignalR endpoint. This is the root cause of the ConnectionId error.
  • The crawler doesn’t correctly handle the polling mechanisms used by SignalR, in particular long-polling, and just sit continuously calling against the endpoint, generating large volumes of requests and their related errors.

In the case of the site that had the issue in this case, this was causing severe performance problems due to the small scale of the site/web server and the number of requests that were coming in.

The fix: robots.txt

Happily the solution is simple enough, and uses robots.txt, the text file that can be placed in a site to specify the required behaviour of visiting web crawlers. You can read more about this file on this site if you’re not familiar with it.

The fix then is to add a robots.txt file to the site:

  1. Create a robots.txt file in the root of the web application
  2. Add content to the file based on the options below
  3. Check that the robots.txt file is visible by visiting the site using the site root url + “robots.txt” (eg http://jonegerton.com/robots.txt)
  4. If your site uses authentication it may be necessary to make sure that robots.txt can be reached by a non-authenticated session

The content used in robots.txt is straightforward:

Allow indexing except for SignalR

Adding the following to robots.txt will tell the crawler to ignore SignalR, but index the rest of the site

User-agent: *
Disallow: /signalr/

No indexing

If you don’t want your site to be crawled at all by search engines (say if its a member-login type site) then you can do this by adding:

User-agent: *
Disallow: /

While crawlers don’t have to respect the contents of robots.txt (it’s more of an advisory), the main search engines will do so, and you should see the exceptions stop occurring (and site performance improve if the load from the crawlers was causing any impact).

24 thoughts on “SignalR: The ConnectionId is in the incorrect format – an alternative cause.”

  1. Thank you, I’ve recently been looking for info about this subject for a
    long time and yours is the best I’ve discovered till now.
    However, what concerning the conclusion? Are you sure in regards to the source?

  2. Henna is a semi-permanent and all-natural hair treatment that can have varying outcomes and so it pays to do a test on a modest
    piece of your hair first. There are lots of solution variations and
    so it pays to get some dependable information.

  3. Oh my goodness! Incredible article dude! Thank you so much,
    However I am experiencing difficulties with your RSS.
    I don’t know the reason why I can’t subscribe to it. Is
    there anybody else having identical RSS issues? Anybody who knows the solution will you
    kindly respond? Thanks!!

  4. Greetings! This is my 1st comment here so I just wanted to give a
    quick shout out and say I truly enjoy reading your articles.
    Can you suggest any other blogs/websites/forums that go
    over the same subjects? Thanks a lot!

  5. Embora contenha poucas palavras da origem estrangeira ou poucas importações, logo no título notamos uma diferença.: A palavra Destak está escrita com K,
    que é uma letra que não existe nas palavras genuinamente portuguesas,
    e seu uso é restringido a poucas importações de
    outras línguas (karate, kizomba, kilómetro etc.) No entanto, temos que
    ter em conta aspecto visual da letra K, cujas formas são muito agudas, que é importante para chamar a atenção dos leitores.

  6. This purely electronic credit exchange program has different benefits, not
    least the reality that it is extremely secure, taking benefit of public and private key cryptography to indicate to the recipient of the Bitcoin payment
    that you are who you say you are, that the Bitcoin belongs to you and
    that the transaction is reputable.

  7. What i don’t understood is if truth be told
    how you’re no longer actually a lot more well-preferred than you might be
    right now. You are very intelligent. You realize thus considerably when it comes to this
    topic, produced me individually consider it from so many various angles.
    Its like men and women aren’t involved unless it is something
    to do with Lady gaga! Your own stuffs excellent.
    Always take care of it up!

  8. Сегодня довольно популярна услуга тонировка
    авто Киев для привнесения оригинальности имиджумашины.
    Кроме того это позволяет сохранить салон автомашины
    от ослепительного солнца и чужих глаз.
    В случае аварии плёнка для тонировки помогает избегнуть рассыпания стекла.
    Это сравнительно простой и доступный прием модернизации автомобиля.

  9. I’ve long suggested that people seeking to gett a good understanding of this speciific topic spread their research acrooss many blogs gdkekfdeedbf

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax