websocket-sharp icon indicating copy to clipboard operation
websocket-sharp copied to clipboard

Connection Failed: Invalid Frame Header in Chrome.

Open Smoozilla opened this issue 11 years ago • 24 comments

The first message works. (Send or Broadcast) but the second message always closes the connection in chrome with

"WebSocket connection to 'ws://localhost/' failed: Invalid frame header"

Oddly enough, Internet Explorer doesn't do this. (IE works fine)

I switched from C# Fleck to this and wasn't having any issues before. I really liked how this library could handle HTTP and Websockets. Thanks.

EDIT: Thought I should mention I'm using HttpServer and AddWebSocketService

Smoozilla avatar Mar 29 '15 23:03 Smoozilla

WebSocket connection to 'ws://localhost/' failed: Invalid frame header in Chrome and opera IE and Firefox works fine

newzyt avatar Apr 02 '15 06:04 newzyt

Same problem here, first works, but the second message always closes the connection in chrome with "WebSocket connection to 'ws://localhost/' failed: Invalid frame header"

Clodo76 avatar Apr 12 '15 11:04 Clodo76

Disabling compression seems to fix this.

Metapyziks avatar Apr 13 '15 09:04 Metapyziks

Same problem here, but it only occurs in Firefox and Firefox Developer Edtion. Always the second message throws this error and close the connection.

14/04/2015 09:32:09|Fatal|WebSocket.processException|WebSocketSharp.WebSocketExc eption: The header part of a frame cannot be read from the data source. em WebSocketSharp.WebSocketFrame.<>c__DisplayClass7 .b__6(Byte[] header) em WebSocketSharp.Ext.<>c__DisplayClass6.b__5(IAsyncResult ar)

code:

    class Program
    {
        static void Main(string[] args)
        {
            var server = new WebSocketServer(8081);
            server.AddWebSocketService<Atualizador>("/");
            server.KeepClean = true;
            server.Start();
            Console.WriteLine("Servidor iniciado");
            string teste = string.Empty;
            while (!teste.Equals("sair"))
            {
                teste = Console.ReadLine();
                server.WebSocketServices.Broadcast(teste);
            }
            server.Stop();
        }
    }

    class Atualizador: WebSocketBehavior { }

In Firefox console I just do:

var ws = new WebSocket("ws://localhost:8081");
ws.onmessage = function(data){alert(data.data);};

hdias2310 avatar Apr 14 '15 12:04 hdias2310

Any news about this? or how to disable compression?

Slyb00ts avatar Apr 15 '15 09:04 Slyb00ts

@Slyb00ts you can disable compression by commenting out / putting something like #if EXT_COMPRESSION around this if statement:

https://github.com/sta/websocket-sharp/blob/master/websocket-sharp/WebSocket.cs#L1074

Metapyziks avatar Apr 15 '15 10:04 Metapyziks

@Metapyziks works for me very well! Thanks very much :smiley:

hdias2310 avatar Apr 15 '15 11:04 hdias2310

I have the same problem trying to connect to websocket from new firefox 37.0.1, but in older firefox it worked. In chrome it works so far. That means something changed in the protocol in firefox

ghost avatar Apr 18 '15 06:04 ghost

I am having the same issue as BBGONE. ~~WebSockets work in Chrome~~ Tested latest from master and gets Invalid frame header in Chrome.

Possibly related: the connection dies after the first message in Firefox 37. Firefox implemented permessage-delate in 37. This is probably related: https://bugzilla.mozilla.org/show_bug.cgi?id=792831

marklieberman avatar Apr 19 '15 02:04 marklieberman

This is probably a similar problem (wrong BFINAL): http://stackoverflow.com/questions/22169036/websocket-permessage-deflate-in-chrome-with-no-context-takeover

berkyl avatar May 05 '15 09:05 berkyl

Hello there,

Could you try the latest code? Thx!

sta avatar May 07 '15 06:05 sta

@sta thanks! Now it works fine in Chrome 42, but was indeed failing after sending a second request

tporadowski avatar May 07 '15 21:05 tporadowski

Second confirm? I don't have the environment nor the time to test myself, thanks

Smoozilla avatar May 08 '15 02:05 Smoozilla

Unfortunately in FF 37.0.2 it fails completely at the moment. I'm testing it from websocket.org/echo.html - a connection is established to WebSocketServer, but after a couple of seconds it throws:

2015-05-08 09:11:40|Fatal|WebSocket.processException:1005|WebSocketSharp.WebSocketException: The header part of a frame cannot be read from the data source.
                             in WebSocketSharp.WebSocketFrame.<>c__DisplayClass7.<ReadAsync>b__6(Byte[] header) w e:\dev\GitHub\websocket-sharp\websocket-sharp\WebSocketFrame.cs:line 566
                             in WebSocketSharp.Ext.<>c__DisplayClass6.<ReadBytesAsync>b__5(IAsyncResult ar) w e:\dev\GitHub\websocket-sharp\websocket-sharp\Ext.cs:line 683
2015-05-08 09:11:40|Trace|WebSocket.close:680|Begin closing the connection.
2015-05-08 09:11:40|Debug|WebSocket.closeHandshake:723|Was clean?: False
                            sent: False
                            received: True
2015-05-08 09:11:40|Trace|WebSocket.close:687|End closing the connection.

tporadowski avatar May 08 '15 07:05 tporadowski

IE 11 works fine

tporadowski avatar May 08 '15 07:05 tporadowski

@sta it works fine for me too with chrome 42, thanks

berkyl avatar May 11 '15 09:05 berkyl

With Firefox 38.0 (as tested on Win7 x64) disabling the option about config for websocket deflate extensions allows the connection to be established. Set "network.websocket.extensions.permessage-deflate" to false and the connection works.

Didn't work out why fully but it might be the disclaimer the author offered w/respect to "Per-message Compression" on https://github.com/sta/websocket-sharp. The status returned by the server clearly indicates this as well by returning the following "Sec-WebSocket-Extensions: permessage-deflate; client_no_context_takeover; server_no_context_takeover"

Perhaps the mozilla authors are assuming something different even though his code or there is a deeper issue. Hopefully this observation will allow the author to look deeper.

dmeade4303 avatar May 12 '15 23:05 dmeade4303

One further note; there is a thread on Stack Overflow regarding a similar issue that may be helpful. See: http://stackoverflow.com/questions/22169036/websocket-permessage-deflate-in-chrome-with-no-context-takeover

dmeade4303 avatar May 13 '15 00:05 dmeade4303

@sta @dmeade4303 when I set WebSocketBehavior.IgnoreExtensions to true when my service is created, so that extensions like compression are disrespected - everything works fine with FF 37

tporadowski avatar May 13 '15 07:05 tporadowski

@sta @tporadowski this makes sense given what I saw. Appears to be the same mechanism underlying it all; something with the server's responses and handling of the "context takeover" if the thread I provided a link to is correct.

dmeade4303 avatar May 13 '15 16:05 dmeade4303