Giter Site home page Giter Site logo

Comments (24)

laimonas avatar laimonas commented on June 8, 2024 2

Hi there is my logs:

I/flutter (17280): Starting HubConnection.
I/flutter (17280): Starting connection with transfer format 'TransferFormat.text'.
I/flutter (17280): Sending negotiation request: https://scrumpokertest.azurewebsites.net/scrum-poker/negotiate.
D/EGL_emulation(17280): eglMakeCurrent: 0x7992b9ef9dc0: ver 3 0 (tinfo 0x7992b9e32f20)
I/flutter (17280): Selecting transport 'HttpTransportType.webSockets'.
I/flutter (17280): (WebSockets transport) Connecting.
I/flutter (17280): WebSocket connected to wss://scrumpokertest.azurewebsites.net/scrum-poker?id=D0riT29u-hAprZq3ss2DdA.
I/flutter (17280): The HttpConnection connected successfully.
I/flutter (17280): Sending handshake request.
I/flutter (17280): (WebSockets transport) sending data. String data of length '32'.
I/flutter (17280): Using HubProtocol 'json'.
I/flutter (17280): WebSocketChannelException: WebSocketChannelException: WebSocketException: Connection to 'https://scrumpokertest.azurewebsites.net:0/scrum-poker?id=D0riT29u-hAprZq3ss2DdA#' was not upgraded to websocket
I/flutter (17280): (WebSockets transport) socket closed.
I/flutter (17280): HttpConnection.stopConnection(null) called while in state ConnectionState.connected.
I/flutter (17280): Connection disconnected.
I/flutter (17280): HubConnection.connectionClosed(null) called while in state HubConnectionState.disconnected.
I/flutter (17280): Hub handshake failed with error 'Exception: The underlying connection was closed before the hub handshake could complete.' during start(). Stopping HubConnection.
I/flutter (17280): Call to HttpConnection.stop(Exception: The underlying connection was closed before the hub handshake could complete.) ignored because the connection is already in the disconnected state.
I/flutter (17280): HubConnection failed to start successfully because of error '{Exception: The underlying connection was closed before the hub handshake could complete..toString}'.

You can try with this url:
https://scrumpokertest.azurewebsites.net/scrum-poker

from signalr_core.

jamiewest avatar jamiewest commented on June 8, 2024

Thank you for your issue, would it be possible for you to share the logs when you connect? I did some basic testing with Azure and will probably need to focus some attention here. Thanks!

from signalr_core.

jamiewest avatar jamiewest commented on June 8, 2024

Just a quick update, I haven't had a chance to start coding a fix yet. The underlying socket is not getting upgraded when connecting. I will need to modify the underlying web_socket_channel library to accept an upgraded socket when not running on the web. I tried testing the web version with your site but failed due to the cors policy. Long polling and server sent events seem to work okay.

from signalr_core.

laimonas avatar laimonas commented on June 8, 2024

Hi @jamiewest tnx for info. I have tried with long polling and it's working for me also (didn't know about this). If you need my azure signalr site to test from web i can try to configure CORS for you if you need, just ping me here and i will look when i have time.

from signalr_core.

jamiewest avatar jamiewest commented on June 8, 2024

I made some progress but I am not receiving at 503 (service unavailable) error from your backend. Any ideas?

from signalr_core.

laimonas avatar laimonas commented on June 8, 2024

@jamiewest 503 error is probably because of site is running in free plan only 60 min execution per day. I have upgraded the service plan and it should be online for all day.
Also if you want to test some hub actions there is:

connection.invoke('CreateGroup', args: ['Group name, 'User name']);
connection.on('GroupCreated', (response) async {
});

from signalr_core.

jamiewest avatar jamiewest commented on June 8, 2024

I am waiting to see if a pull request is accepted regarding #387 in package:http/http.dart. If this is accepted then I will be able to provide a mechanism to handle bad certificate callbacks and other security context concerns along with allowing the socket to be upgraded. This should in part resolve the issue your having.

I did end up pushing my own SignalR app in an Azure App Service plan, the free one, to see if I could recreate the problems you are having. During the process it asked specifically if I wanted to enable websockets, which I did. I think yours might me missing this piece, you can check this by going into the app service/configuration/general settings area and make sure the radio button is enabled for web sockets.

from signalr_core.

laimonas avatar laimonas commented on June 8, 2024

@jamiewest websockets are enabled. I just made another test. I have two apps on azure one is based on windows and other on linux service plan. And yes it is working with windows but not the linux one. So i don't know if this is a bug with library or azure it self. Maybe you can try with linux service plan (it is much cheaper then windows based).

from signalr_core.

laimonas avatar laimonas commented on June 8, 2024

@jamiewest somehow i cannot reproduce this anymore on linux instance of azure it is even started to work with " transport: HttpTransportType.webSockets". I have also tested with flutter web and it is also working with one thing that i need to disable skipNegotiation. So you can close this one!

from signalr_core.

jamiewest avatar jamiewest commented on June 8, 2024

Okay, thanks. Once the http package is published with my changes I will publish this library with a handful of bug fixes. Hopefully soon...

from signalr_core.

sawproduction avatar sawproduction commented on June 8, 2024

have you solved this I'm getting this error after 2 years of yours

from signalr_core.

MathiasTP avatar MathiasTP commented on June 8, 2024

I am getting this error as well..

from signalr_core.

aminesnip avatar aminesnip commented on June 8, 2024

I am getting this error as well.
When I test locally on windows it works very well, but the error appears when I publish on the linux server.
Any solution to fix this problem ?.

from signalr_core.

frkn2076 avatar frkn2076 commented on June 8, 2024

I was facing the same issue and stopping hubConnection before super.dispose solved my issue.

@override
  void dispose() {
    hubConnection.stop();  // I've added that line.
    super.dispose();
  }

from signalr_core.

sinanhaci avatar sinanhaci commented on June 8, 2024

I am getting this error as well. When I test locally on windows it works very well, but the error appears when I publish on the linux server. Any solution to fix this problem ?.

Were you able to solve the problem?

from signalr_core.

andres-aranda avatar andres-aranda commented on June 8, 2024

Me enfrentaba al mismo problema y detuve hubConnection antes de que super.dispose resolviera mi problema.

@override
  void dispose() {
    hubConnection.stop();  // I've added that line.
    super.dispose();
  }

eso en que archivo lo agregaste?

from signalr_core.

sinanhaci avatar sinanhaci commented on June 8, 2024

This issue usually occurs on Linux servers, in my experience, it's not related to the package itself, but rather to the server configurations.

from signalr_core.

mamaly12 avatar mamaly12 commented on June 8, 2024

I still have the same issue. I use IdentityServer 4, and the following setup is recommended for signal authentication using the access token(according to https://learn.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-7.0#identity-server-jwt-authentication).

It's not related to the OS, and I am suspicious it's related to the library that cannot update the connection.

  var originalOnMessageReceived = options.Events.OnMessageReceived;
            options.Events.OnMessageReceived = async context =>
            {
                await originalOnMessageReceived(context);

                if (string.IsNullOrEmpty(context.Token))
                {
                    var accessToken = context.Request.Query["access_token"];
                    var path = context.HttpContext.Request.Path;

                    if (!string.IsNullOrEmpty(accessToken) &&
                        path.StartsWithSegments("/hubs"))
                    {
                        context.Token = accessToken;
                    }
                }
            };

When I start a socket connection request, everything seems fine, and the " context.Token" will be set according to the token. Still, suddenly, I received the error "The underlying connection was closed before the hub handshake could complete." from Flutter and my connection will be closed

from signalr_core.

madagaskarr avatar madagaskarr commented on June 8, 2024

I think the issue is on the server, try changing the connection protocol to long pooling

from signalr_core.

kivocsa99 avatar kivocsa99 commented on June 8, 2024

@madagaskarr
iam having the same issue what do you mean by changing it to long pooling and how to do that ?

from signalr_core.

kivocsa99 avatar kivocsa99 commented on June 8, 2024

@jamiewest
any updates on this ?

from signalr_core.

madagaskarr avatar madagaskarr commented on June 8, 2024

I fixed this on the nginx server by adding support to upgrade the connection. The library work as expected!

from signalr_core.

kivocsa99 avatar kivocsa99 commented on June 8, 2024

@madagaskarr iam using IIS any suggestions ?

from signalr_core.

DmitryGaimaldinov avatar DmitryGaimaldinov commented on June 8, 2024

In my case the problem happened only when I was using [Authrize] attribute in hub.
I added JwtBearerEvents handler, and everything started working.

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
        {
            options.TokenValidationParameters = new TokenValidationParameters
            {
                ...
            };
            options.MapInboundClaims = false;
            options.Events = new JwtBearerEvents
            {
                OnMessageReceived = context =>
                {
                    var path = context.Request.Path;
                    var accessToken = context.Request.Query["access_token"];
                   // Here also was a check "path.StartsWithSegments("/hubs")" like the documentations suggests, but it caused websocket error so I removed it
                    if (!string.IsNullOrEmpty(accessToken))
                    {

                        context.Request.Headers.Add("Authorization", new[] { $"Bearer {accessToken}" });
                    }
                    return Task.CompletedTask;
                }
            };
        });

from signalr_core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.