SignalR error during negotiation request while testing Vagrant VM

I installed a console application that just starts the loop and emits a message using Signal R. The listener that listens is an angular application.

When I run locally (both the console application and the angular site), it works fine. However, when I run the console application in my Vagrant VM (Ubuntu HOST), I get a too familiar error message, for example the following:

GET http://localhost:12345/signalr/negotiate?clientProtocol=1.5&userId=12345&connectionData=%5B%7B%22 name%22%3A%22testem itter%22%7D%5D&_=1446565284280 500 (Internal Server Error) 

I ran into problems like this before (maybe that's for sure), so here are some source data

The code I have is as follows:

  namespace test { public class Program { public static void Main(string[] args) { try { using (WebApp.Start<EmmitStartup>("http://*:12345")) { Console.Out.WriteLine("Emmit started on http://*:12345"); IEmitterFactory factory = new EmitterFactory(); while (true) { Thread.Sleep(5000); ITestEmitter emitter = factory.Create((ctx) => { return new TestEmitter(ctx); }); emitter.SayHello(); emitter.Echo("Hello World:" + DateTime.Now); } } } catch (Exception e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); Console.ReadLine(); } } } public class TestEmitter:Emitter,ITestEmitter { public TestEmitter(IEmitterContext emitterContext) : base(emitterContext) { } public TestEmitter(IEmitterContext emitterContext, EmitterModel model) : base(emitterContext, model) { } public TestEmitter(IDictionary<string, object> model) : base(model) { } public void SayHello() { EmitterContext.Clients.All.onSayHello(); } public void Echo(string message) { EmitterContext.Clients.All.onEcho(message); } } public interface ITestEmitter { void SayHello(); void Echo(string message); } public class EmmitStartup { public void Configuration(IAppBuilder app) { app.UseCors(CorsOptions.AllowAll); app.Map("/signalr", map => { map.UseCors(CorsOptions.AllowAll); GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule()); var config = new HubConfiguration() { EnableDetailedErrors = true, EnableJavaScriptProxies = true, EnableJSONP = true }; map.RunSignalR(config); }); } } } 
  • No exceptions or error logs are generated on the server.
  • I have included CORS in SignalR
  • I tried using both http://*:12345 and http://localhost:12345 and http://0.0.0.0:12345
  • The Emmit library is just syntactic sugar and makes a direct pass to SignalR (I tried the same with SignalR directly.
  • I tried different combinations of enable / disable EnableJSONP
  • I know that SignalR works and is accessible through VM, because I can click http://localhost:12345/signalr/hubs and it shows the proxy file.
  • I have a setup port for Vagrant VM for port 12345
  • I disabled the firewall on VM HOST (Ubuntu) using sudo ufw disable

The code for the client is as follows:

  var emmitProxy = null; Emmit.createProxy({ emitter:'testEmitter', path:'http://localhost:12345/signalr', listeners:{ 'onSayHello':function(){ $log.info('onSayHello triggered') }, 'onEcho':function(message){ $log.info(message); } }, onError:function(){ //an error occured $log.error('testEmitter:onError'); }, onDisconnected:function(){ //proxy was disconnected $log.debug('testEmitter:onDisconnected'); }, queryParams:{ userId:'12345' //optional } }).then(function(newProxy){ emmitProxy = newProxy; }); 

UPDATE

I turned on logging and here is the conclusion. Before another person recommends that I enable CORS, I donโ€™t think CORS is a problem, I think itโ€™s just a cascading effect of something else that causes the problem.

enter image description here

UPDATE

I ran this in several environments with the following results:

  • Ran in Docker container on Vagrant VM (Ubuntu) - ERROR OCCURS
  • Ran straight to Vagrant VM (Ubuntu) - ERROR OCCURS
  • Deployed in a Docker to Tutum container - ERROR OCCURS
  • Ran directly through Visual Studio on Windows - ALL WORKS
  • Ran directly on Mac oSX (obviously on Mono) - ALL WORKS

I added the following IHubPipelineModule

 public class ErrorHandlingPipelineModule:HubPipelineModule { public override Func<HubDescriptor, IRequest, bool> BuildAuthorizeConnect (Func<HubDescriptor, IRequest, bool> authorizeConnect) { try { Console.Out.WriteLine ("BuildAuthorizeConnect"); return base.BuildAuthorizeConnect (authorizeConnect); } catch (Exception exception) { Console.Out.WriteLine ("AuthorizeConnect Failure"); Console.Out.WriteLine(exception.Message); } return base.BuildAuthorizeConnect(authorizeConnect); } protected override void OnAfterDisconnect (IHub hub, bool stopCalled) { try { Console.Out.WriteLine ("OnAfterDisconnect"); base.OnAfterDisconnect (hub, stopCalled); Console.Out.WriteLine ("After OnAfterDisconnect"); } catch (Exception exception) { Console.Out.WriteLine ("AfterDisconnect Failure"); Console.Out.WriteLine(exception.Message); } } protected override bool OnBeforeDisconnect (IHub hub, bool stopCalled) { try { Console.Out.WriteLine ("OnBeforeDisconnect"); return base.OnBeforeDisconnect (hub, stopCalled); } catch (Exception exception) { Console.Out.WriteLine ("BeforeDisconnect Failure"); Console.Out.WriteLine(exception.Message); } return base.OnBeforeDisconnect (hub, stopCalled); } public override Func<IHub, System.Threading.Tasks.Task> BuildConnect(Func<IHub, System.Threading.Tasks.Task> connect) { try { Console.Out.WriteLine("BuildConnect"); return base.BuildConnect(connect); } catch (Exception exception) { Console.Out.WriteLine(exception.Message); } return base.BuildConnect(connect); } protected override void OnAfterConnect(IHub hub) { try { Console.Out.WriteLine("OnAfterConnect"); base.OnAfterConnect(hub); } catch (Exception exception) { Console.Out.WriteLine ("OnAfterConnect Failure"); Console.Out.WriteLine(exception.Message); } } protected override bool OnBeforeConnect(IHub hub) { try { Console.Out.WriteLine("OnBeforeConnect"); return base.OnBeforeConnect(hub); } catch (Exception exception) { Console.Out.WriteLine ("OnBeforeConnect Failure"); Console.Out.WriteLine(exception.Message); } return base.OnBeforeConnect (hub); } } 

And when I check my magazines, the only printable magazines are the following:

  BuildConnect BuildAuthorizeConnect 

UPDATE I'm not sure if this will be relevant or how I might have missed it, but I checked the answer from 500 and posted it in here

It looks like it shows that it is associated with Improperly protected user key pairs in '/root/.config/.mono/keypairs'.

Also, I'm not sure if this link contains confidential information. If someone can tell me if this happens, I would appreciate it.

I still did a minimal amount of research and came across SignalR.Owin runs on Windows but returns 500 for Mono on Linux

When I check the Network tab for a reconciliation request, I get the following

** Headers ** Remote Address: 127.0.0.1:12345 Request URL: http: // localhost: 12345 / signalr / negotiate? ClientProtocol = 1.5 & userId = 12345 & connectionData =% 5B% 7B% 22name% 22% 3A% 22testemitter% 22% 7D% 5D & _ = 1446964166640 Request method: GET Status code: 500 Internal server error

  HTTP/1.1 500 Internal Server Error Access-Control-Allow-Origin: http://localhost:8100 Access-Control-Allow-Credentials: true X-Content-Type-Options: nosniff Content-Type: text/html Server: Mono-HTTPAPI/1.0 Date: Sun, 08 Nov 2015 06:30:28 GMT Connection: close Transfer-Encoding: chunked Accept:text/plain, */*; q=0.01 Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Content-Type:application/x-www-form-urlencoded; charset=UTF-8 Cookie:JSESSIONID.ae4b31f4=aqpz31hevinaauwftyijure; JSESSIONID.26c95422=1m32u58exuvjz5jrojszqziqh; JSESSIONID.3fd19426=iv9fawaej3nt14yzcruj45si5; JSESSIONID.8868ba42=1gh4w06alx8ehuuj1adr5w8y8; JSESSIONID.947cfb91=nyxfrp6u0pny1sl8gwlouprh4; screenResolution=1280x800 Host:localhost:12345 Origin:http://localhost:8100 Pragma:no-cache Referer:http://localhost:8100/ User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36 
+6
source share
2 answers

Although your application contains app.UseCors(CorsOptions.AllowAll) , the original error message is pretty clear that this is a CORS problem.

The original error message

The Origin URL ( http: // localhost: 8100 ) is different from the SignalR server URL ( http: // localhost: 12345 ). With CORS, the schema, domain, and port must match; in this case, the port is different.

Here's what to do:

  • Make sure the URLs are actually correct and are what you expect. (Port 8100).
  • Capturing HTTP traffic on the client. You can do this using Fiddler or a similar tool. You can also just use the "network" tab of the chrome debugger.
  • Make sure the start page load contains the CORS header. You should see Access-Control-Allow-Origin: in the response header. Based on how you configured it, the value should be: *

... I believe the problem is that you enabled CORS on the SignalR server (port 12345), but CORS needs to be enabled on your web server. (Port 8100)

EDIT

The original question has been edited. With the addition of HTTP headers, the error message changed from a CORS question to a 500 error.

 CryptographicException: Improperly protected user key pairs in '/root/.config/.mono/keypairs'. ... CryptographicException: Data protection failed. System.Security.Cryptography.ProtectedData.Protect (System.Byte[] userData, System.Byte[] optionalEntropy, DataProtectionScope scope) [0x00000] Microsoft.AspNet.SignalR.Infrastructure.DefaultProtectedData.Protect (System.String data, System.String purpose) [0x00000] 

I have done a minimal amount of research so far and stumbled upon SignalR.Owin runs on Windows but returns 500 for Mono on Linux

The GitHub Issue that you have precisely linked to what you described. Since it is marked closed, the obvious question is to find out if what is described on the ticket applies. From the ticket:

davidfowl commented on May 22, 2013 - I just fixed the build in the dev branch yesterday. It requires mono 3.0.10 to run and works fine now.

So check out two things:

  • Mono version installed on your server. The ticket says that Mono 3.0.10 is needed. What is your version?
  • SignalR must include changes. It is one or both. Make sure that any version of SignalR you are using includes the following changes:

Finally, if you need to, you have the option to enter your own version of SignalR.Core / Infrastructure / DefaultProtectedData.cs. You can simply install it in the OWIN pipeline . From SignalR Source Code :

  // Use the data protection provider from app builder and fallback to the // Dpapi provider IDataProtectionProvider provider = builder.GetDataProtectionProvider(); IProtectedData protectedData; 
+3
source

See the selected answer for an understanding of the problem and a possible solution.

I solved the problem by making sure I have Mono version 3.0.10 or later. I use Docker, so it was as simple as updating my FROM statement in my Docker file.

0
source

All Articles