Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Azure SignalR Service is not connected yet, please try again later. in local environment #909

Closed
thusithagh opened this issue May 21, 2020 · 11 comments

Comments

@thusithagh
Copy link

thusithagh commented May 21, 2020

Hello!
I've been getting above error since yesterday when I'm debugging my MVC webapp locally via VS 2019. The error comes from the negotiate request which is something like below:

http://localhost:53652/signalr/negotiate?clientProtocol=2.1&connectionData=

I've deployed it to one of our Dev servers in Azure cloud, and now that too getting the same error and SignalR is not workable. However, SignalR is still working fine in our Production servers.

I've followed this: #452
And this: https://forums.asp.net/t/2154631.aspx?Error+500+using+Azure+SignalR+service
But still no use.
After enabling diagnostics as per the first link, I was getting an error saying that I cannot connect to our Azure SignalR instance. But I don't get it since, the production servers can connect and working fine.

I was in Azure SignalR v1.2.3, and later updated to v1.4.3 thinking that would resolve. But still no luck.

My Startup class:

public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            Microsoft.AspNet.SignalR.GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(60);

//Works for app.MapSignalR();
            app.MapAzureSignalR(appname));
            
        }
       
    }

Any help will be highly appreciated.
Thank you.

@vicancy
Copy link
Member

vicancy commented May 21, 2020

Could you try https://github.com/Azure/azure-signalr/blob/c764ee716b0b6079d4085c1c68d02c29be3c8aea/docs/tsg.md#troubleshooting-guide-1 to see what is the exception thrown? Probably the 500 error is caused by some assembly binding issue, have you updated any reference package versions in your local environment?

@thusithagh
Copy link
Author

thusithagh commented May 21, 2020

@vicancy I've got this --> Azure SignalR Service is not connected yet, please try again later.
Stacktrace: at Microsoft.Azure.SignalR.AspNet.DefaultEndpointRouter.GetNegotiateEndpoints(IEnumerable`1 endpoints)

Other than that whole lot of The remote server returned an error: (400) Bad Request.

I haven't updated any packages recently. Which puzzles me is that, the same code works fine in Production environment but not in local. Maybe the Production servers too will give the same error if we reset IIS.

@thusithagh
Copy link
Author

Ok. This seems to have started working again. I suspect something went wrong at Azure's end and they have corrected it now.
Thank you for anyone who was looking into this.

@vicancy
Copy link
Member

vicancy commented May 22, 2020

Yes we've identified an issue when user is using ASP.NET SignalR protocol

Symptom

The server connection might unable to connect to Azure SignalR with 400 status code.

Root cause

The latest version of Azure SignalR added a stricter validation rule for ASP.NET SignalR application name and hub names that app servers with hub names containing characters like - % will be impacted and get 400 response

Solution

We have rolled back the validation check and have fixed the impacted resources and the issue should be gone now.

@thusithagh
Copy link
Author

Thank you @vicancy .
Lucky enough that this didn't affect our production servers. It was a waste of time at work however :(

@davidkallesen
Copy link

I ran into this problem Azure SignalR Service is not connected yet and get httpstatus 502 in Fidler when I do this in my program.cs for my webapi:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((context, config) => config.ConfigureKeyVault())
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })

But it works do this instead:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((context, config) => config.ConfigureKeyVault())
                .UseStartup<Startup>();

For both senerios in startup.cs:

public void ConfigureServices(IServiceCollection services)
{
        services
            .AddSignalR()
            .AddAzureSignalR();
}

I am using netcoreapp3.1 with package Microsoft.Azure.SignalR version 1.6.1 and would use IHostBuilder but don't know how to set it up, without going the IWebHostBuilder way.

  1. What do I do wrong?
  2. Maybe it can give a clue to other with the problem Azure SignalR Service is not connected yet

@vicancy
Copy link
Member

vicancy commented Dec 18, 2020

@davidkallesen Besides Azure SignalR Service is not connected yet, what are the logs for Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport and Microsoft.Azure.SignalR.ServiceConnection when the app starts, as similar to:

info: Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport[1]
      Starting transport. Transfer mode: Binary. Url: 'ws://.../server/?hub=benchhub&cid=03b803d1-0074-4078-958c-ca9491d981f1'.
fail: Microsoft.Azure.SignalR.ServiceConnection[2]
      Failed to connect to '(Primary)http://...', will retry after the back off period. Error detail: Unable to connect to the remote server. No connection could be made because the target machine actively refused it.. Id: 7363a945-4f74-43bc-85af-cf187f397a67

@nyakimov
Copy link

I ran into this problem Azure SignalR Service is not connected yet and get httpstatus 502 in Fidler when I do this in my program.cs for my webapi:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((context, config) => config.ConfigureKeyVault())
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })

But it works do this instead:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((context, config) => config.ConfigureKeyVault())
                .UseStartup<Startup>();

For both senerios in startup.cs:

public void ConfigureServices(IServiceCollection services)
{
        services
            .AddSignalR()
            .AddAzureSignalR();
}

I am using netcoreapp3.1 with package Microsoft.Azure.SignalR version 1.6.1 and would use IHostBuilder but don't know how to set it up, without going the IWebHostBuilder way.

  1. What do I do wrong?
  2. Maybe it can give a clue to other with the problem Azure SignalR Service is not connected yet

In your Startup.cs do you have a line similar to this: services.AddHostedService(); ? Also inside of that worker are you trying to send out a signalR message ? If you are then that's what might be causing your issues. At least for me that's what it was. The hosted service (Worker) would start up and run before the AzureSignalR connection is established so it would blow up the whole project with the exact same error you're seeing. All I did for right now is added a Task.Delay(10000) to let the project start up. I'll be interested to find out if there is a way to tell if the AzureSignalR connection has been established before sending anything through the HubContext.

@gyanex
Copy link

gyanex commented May 19, 2021

@vicancy @davidkallesen Besides Azure SignalR Service is not connected yet, what are the logs for Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport and Microsoft.Azure.SignalR.ServiceConnection when the app starts, as similar to:

info: Microsoft.Azure.SignalR.Connections.Client.Internal.WebSocketsTransport[1]
      Starting transport. Transfer mode: Binary. Url: 'ws://.../server/?hub=benchhub&cid=03b803d1-0074-4078-958c-ca9491d981f1'.
fail: Microsoft.Azure.SignalR.ServiceConnection[2]
      Failed to connect to '(Primary)http://...', will retry after the back off period. Error detail: Unable to connect to the remote server. No connection could be made because the target machine actively refused it.. Id: 7363a945-4f74-43bc-85af-cf187f397a67

Microsoft.Azure.SignalR.Common.AzureSignalRNotConnectedException: Azure SignalR Service is not connected yet, please try again later.
at Microsoft.Azure.SignalR.ServiceConnectionManager1.WriteAsync(ServiceMessage serviceMessage) at Microsoft.Azure.SignalR.ServiceLifetimeManagerBase1.<>c__DisplayClass22_01.<WriteAsync>b__0(T m) at Microsoft.Azure.SignalR.ServiceLifetimeManagerBase1.WriteCoreAsync[T](T message, Func2 task) at Beo.Hardware.IOT.API.Controllers.BEODeviceController.AddBEOMasterDeviceFeedintoDB(BeoDeviceModel data) in D:\BEO\Beo.Warehouse\Beo.Hardware.IOT.API\Controllers\BEODeviceController.cs:line 26 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

@antongenis
Copy link

Make sure u register:
app.UseAzureSignalR(route => { route.MapHub(signalRConfigurationSettings.HubPath); });

before the instantiation of your class that uses the

IHubContext someHub, in it constructor

I instantiate it like this
serviceProvider.GetService()

@mohamadbahmani
Copy link

I had the same issue Getting Azure SignalR Service is not connected yet, please try again later and I realized that the access key in my azure connection string is wrong! I had changed the endpoint address(service) without changing the access key!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants