Websocket connection fails

822 views
Skip to first unread message

Alex B

unread,
Nov 29, 2015, 9:07:07 PM11/29/15
to golang-nuts

I built a websocket server for an social network, and I am getting weird errors like below when receiving messages:

failed: Could not decode a text frame as UTF-8.

When this happens it drops the socket connection.

I have built quite a few socket-enabled Go apps before and it has always been very reliable. I tried searching for other similar issues, but they are all quite old, and not related to Go.

My system stores a buffer of socket messages for different feeds, and it seems like random messages at random times trigger the error when serving the latest messages in the buffer.

Please help



Jesse McNelis

unread,
Nov 29, 2015, 9:55:49 PM11/29/15
to Alex B, golang-nuts
On Mon, Nov 30, 2015 at 1:07 PM, Alex B <3du...@gmail.com> wrote:
>
> I built a websocket server for an social network, and I am getting weird
> errors like below when receiving messages:
>
> failed: Could not decode a text frame as UTF-8.
>
> When this happens it drops the socket connection.

https://tools.ietf.org/html/rfc6455#section-8.1

Some part of your system is trying to send/receive data that isn't
validate UTF-8 as a 'text' type websocket message.
You need to verify that text being sent as a 'text' type message is
UTF-8 before sending it.

It's possible you've got a client sending incorrectly encoded text.

My bet is you've not noticed the issue before because you haven't sent
multibyte characters in the past and just recently started sending
emojis.

Alex B

unread,
Nov 30, 2015, 8:25:38 AM11/30/15
to golang-nuts, 3du...@gmail.com, jes...@jessta.id.au

This is a JS client error so it it Go which is sending the non-utf8 chars.

I dont have any emoji, as it is just basic tweet style messages (such as 'hello world') I am sending which I have written myself.

The tweets send fine many times, but randomly the connection just breaks on messages which were previously sent fine. I have a buffer so when you load the webpage it syncs the most recent 50 messages with the client, or forwards new messages in realtime.

Alex B

unread,
Nov 30, 2015, 8:40:58 AM11/30/15
to golang-nuts, 3du...@gmail.com, jes...@jessta.id.au

Personally I suspect this error stems from using map[*][]byte to store the JSON encoded tweets.

Every time I try and store []byte in a map, I always get corruption of data, I have experienced this with storing ciphertext bytes many times, but thought this can't be possible hence why I have tried again to use a map of bytes.

Oh well, I will just have to use map[*]string again...

Tamás Gulácsi

unread,
Nov 30, 2015, 4:20:14 PM11/30/15
to golang-nuts
Probably you reuse those slices, not copy them before inserting into that map...
Reply all
Reply to author
Forward
0 new messages