Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

IIS recycle app pool: the connection id is in the incorrect format. #1680

Closed
dsaf opened this Issue · 16 comments

4 participants

@dsaf

Notes:

SignalR version: 1.0.1.
Transports used: LongPolling, ServerSentEvents.
Hosted via ASP.NET MVC 4 on IIS 6.

Scenario:

Deploy server to IIS, start client, test client works, recycle server application pool, client starts spitting reconnect errors (500).

IIS log message:

Exception information:
Exception type: InvalidOperationException
Exception message: The connection id is in the incorrect format.

Server stack trace:
at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken)
at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context)
at Microsoft.AspNet.SignalR.Owin.CallHandler.Invoke(IDictionary2 environment)
at Microsoft.AspNet.SignalR.Owin.Handlers.HubDispatcherHandler.Invoke(IDictionary
2 environment)
at Microsoft.Owin.Host.SystemWeb.OwinCallContext.Execute()
at Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object extraData)

Request information:
Request URL: http://remoteserver:12321/signalr/?transport=longPolling&connectionToken=bf82Cvcy7etnOyECjhmqhqqS8tQ_1EAuTGWjwi5wAiKmRS5lNXd3aa6mFHsgJHGCuqkm5tXfEkgkmXIaPjREkaoOE6r0HXX-QsC6ypbrwRK-7_LjmK6P-DhfK6dZa9MWhl4A-AJomQaaEm7ZPAbovg2&messageId=B,2|C,0|D,0|E,0&connectionData=[{"Name":"ChatHub"}]

or

Request URL: http://remoteserver:12321/signalr/send?transport=serverSentEvents&connectionToken=qWtm2q4gklGr0A89JQ0z6y80NQDJ71Sw3HKtWiT8WJ6Yb2jNwP6uF1tEa0rAZds34KJpNI7Y_ZSUT7bA2JOv_Y83wwJ9HpggzF7p9zBGUBAE4qpa8Ijv_5eZ7oQupoqskWSUMCHRAmXxksFikJ-Mng2

Client code:

    public static void Main(string[] args)
    {
        var hubConnection = new HubConnection("http://remoteserver:12321/");

        var chat = hubConnection.CreateHubProxy("ChatHub");
        hubConnection.StateChanged += change => Console.WriteLine("< was {0} now {1}.", change.OldState, change.NewState);
        hubConnection.Error += exception => Console.WriteLine("< Error (connection event): {0}", exception.GetInnerMessages());

        chat.On("addMessage", message => Console.WriteLine("> {0}",message));

        hubConnection.Start(new ServerSentEventsTransport()).Wait();

        string line;
        while ((line = Console.ReadLine()) != null)
        {
            try
            {
                chat.Invoke("Send", line).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("< Error (on invoke): {0}", ex.Message);
            }
        }
    }

Server code:

    public class ChatHub : Hub
    {
            public void Send(string message)
            {
                Clients.All.addMessage(message);
            }
     }

Thank you.

@davidfowl
Owner

Are you doing authentication?

@dsaf

I started by using default IIS configuration. Then I tried switching to Anonymous and also using this code:

hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;

Is there something specific you would like me to try?

@abnanda1 abnanda1 was assigned
@davidfowl
Owner

Ca you reproduce this on IISExpress?

@dsaf

I do not think so, because IIS Express has been used by us for weeks during development until deployment. But I will need to double-check to say definitely (when I am in the office next morning GMT).

@davidfowl
Owner

@dsaf ok, let me know if your iis setup is using ANY type of authentication. We need the exact configuration settings so that we understand what the issue is. This type of issues usually shows up when doing auth.

@dsaf

I checked that the issue is still there when:

  1. web.config has <authentication mode="None" />
  2. IIS->Authentication has Anonymous Authentication enabled and everything else disabled. When I disable everything including Anonymous Authentication the following error is thrown on start: "The remote server returned an error: (401) Unauthorized.".
  3. Removed this line (no credentials are set): hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials.

PS: eventually when released we would like to use Windows authentication.

@davidfowl
Owner

@dsaf Authentication itself isn't broken see the explaination here #1589 (comment). It should be easy to repro if you're using the default settings and authentication isn't involved in any way.

@dsaf

I tried and could not reproduce the issue using IIS Express:

  1. Start two client apps and a server web app.
  2. Kill iisexpress process.
  3. Clients get this error: "An existing connection was forcibly closed by the remote host".
  4. Clients can reconnect when web app is started again.
@dsaf

@davidfowl I am not using any authentication as far as I can see. Is there anything else I can do?

@davidfowl
Owner

Seems like it's a crypto error:

SignalR.PersistentConnection Information: 0 : Failed to process connectionToken 78YTjdnErbAmtontqYSaxyeQULxbMPGBMx1P32skuh3Hjuj2ZLBrqUAWe071UKuWHxB8sjvBv-0FaMQHmpXBLwL6R4eU1k95nMgvxw_s2IAb_FiKhvnrCxikUv7VeDpv0: System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.
   at System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func, Byte[] input)
   at Microsoft.AspNet.SignalR.SystemWeb.Infrastructure.MachineKeyProtectedData.Unprotect(String protectedValue, String purpose)
   at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken)
@davidfowl
Owner

Turns out this isn't a SignalR issue. The problem seems to be in some older version of asp.net/iis or something else a new machine key is being generated per app pool recycle.

@davidfowl davidfowl closed this
@jalchr

I'm getting the same error, while I'm debugging an asp.net mvc 4 on .net 4.5. When I change some code and run the project again ... I got this:

The connection id is in the incorrect format.

Server stack trace:
at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken)
at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context)
at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.ProcessRequest(HostContext context)
at Microsoft.AspNet.SignalR.Owin.CallHandler.Invoke(IDictionary2 environment)
at Microsoft.AspNet.SignalR.Owin.Handlers.HubDispatcherHandler.Invoke(IDictionary
2 environment)
at Microsoft.Owin.Host.SystemWeb.OwinCallContext.Execute()
at Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object extraData)

Exception rethrown at [0]:
at MvcApplication.Application_Error(Object sender, EventArgs e) in c:\Code\Global.asax.cs:line 82
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.HttpApplication.RaiseOnError()

@dsaf

If you are using full IIS then try changing machine key to concrete generated value.

@jalchr

Sorry for missing info ... this is actually running on IIS Express .... can I safely ignore this when running in production on Full IIS ?

@davidfowl
Owner

@jalchr are you using any authentication? If you look at the title of the issue it says IIS recycle app pool: the connection id is in the incorrect format. If you're seeing this on IIS Express then it's not related to this problem even though the error message might be the same.

Take a look at these bugs:

Do you have a specific sequence of steps that you can repeat to cause this issue? If you're using any type of auth, read #1589 (comment) and see if you're having that problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.