rstudio / websocket

WebSocket client for R
https://rstudio.github.io/websocket/
Other
92 stars 18 forks source link

Control frame received with opcode 8 #58

Open SatoshiReport opened 5 years ago

SatoshiReport commented 5 years ago

I get this error message several times a day from two different web socket connections: "Control frame received with opcode 8"

I don't see anything unusual and it runs for hours and then it just disconnects. The funny thing is that tryCatch never catches it.

[2019-08-22 18:46:41] [control] Control frame received with opcode 8
[2019-08-22 18:46:41] [frame_header] Dispatching write containing 1 message(s) containing 6 header bytes and 2 payload bytes
[2019-08-22 18:46:41] [frame_header] Header Bytes: 
[0] (6) 88 82 E6 F3 1B 81 

[2019-08-22 18:46:41] [frame_payload] Payload Bytes: 
[0] (2) [8] E5 1B 

$target
<WebSocket>
  Public:
    clearAccessLogChannels: function (channels = c("all")) 
    clearErrorLogChannels: function (channels = c("all")) 
    clone: function (deep = FALSE) 
    close: function (code = 1000L, reason = "") 
    connect: function () 
    initialize: function (url, protocols = character(0), headers = NULL, autoConnect = TRUE, 
    onClose: function (callback) 
    onError: function (callback) 
    onMessage: function (callback) 
    onOpen: function (callback) 
    protocol: function () 
    readyState: function () 
    send: function (msg) 
    setAccessLogChannels: function (channels = c("all")) 
    setErrorLogChannels: function (channels = c("all")) 
  Private:
    accessLogChannels: function (channels, stompValue) 
    accessLogChannelValues: none connect disconnect control frame_header frame_paylo ...
    callbacks: environment
    errorLogChannels: function (channels, stompValue) 
    errorLogChannelValues: none devel library info warn rerror fatal all
    getInvoker: function (eventName) 
    handleIncoming: function () 
    pendingConnect: FALSE
    scheduleIncoming: function () 
    wsObj: externalptr

$code
[1] 1000

$reason
[1] ""

Error: Disconnected with code  1000 
[2019-08-22 18:46:41] [disconnect] Disconnect close local:[1000] remote:[1000]
[2019-08-22 18:46:41] [info] asio async_write error: asio.ssl:337690831 (protocol is shutdown)
[2019-08-22 18:46:41] [fatal] handle_write_frame error: websocketpp.transport:2 (Underlying Transport Error)
alandipert commented 5 years ago

Hi, thanks for the report. Do you by any chance know what kind of server you're dealing with, or otherwise have suggestions about how we might reproduce?

I haven't seen this error before, but I'm eager to hear any more specifics you might have to see if I can reproduce it.

SatoshiReport commented 5 years ago

Apologies for the delay. I am connected to Bitfinex, a crypto exchange. Here is the minimum code needed to reproduce the issue. I just ran this and got the error in under 24 hours.

library(websocket)
library(jsonlite)

url <- "wss://api.bitfinex.com/ws/2"

ws <- websocket::WebSocket$new(url=url, accessLogChannels = "all", 
errorLogChannels = "all") 

ws$onOpen(function(event) {
  ws$send('{"event": "subscribe", "channel": "trades", "symbol": "tBTCUSD"}')
})

ws$onMessage(function(event) {
  print(fromJSON(event$data))
})

ws$onClose(function(event) {
  cat("Error: Client disconnected with code ", event$code, "\n")
})

ws$onError(function(event) {
  cat("Error: Client failed to connect: ", event$message, "\n")
})

httpuv::service(Inf)
SatoshiReport commented 5 years ago

Here is another crypto exchange where the crash happens quicker, within 30 minutes or so. Note, I run this code as a file (r file.R) as opposed to within R Studio.

library(websocket)
library(jsonlite)
library(httpuv)

url <- "wss://www.deribit.com/ws/api/v2"

ws <- websocket::WebSocket$new(url=url, accessLogChannels = "all", errorLogChannels = "all") 

ws$onOpen(function(event) {
  ws$send('{"jsonrpc" : "2.0","method" : "public/subscribe", "params" : {"channels":["perpetual.BTC-PERPETUAL.raw"]}}')
})

ws$onMessage(function(event) {
  print(fromJSON(event$data))
})

ws$onClose(function(event) {
  cat("Error: Client disconnected with code ", event$code, "\n")
})

ws$onError(function(event) {
  cat("Error: Client failed to connect: ", event$message, "\n")
})

httpuv::service(Inf)
alandipert commented 5 years ago

Thank you for the updates, I'll try this out.

Have you by any chance accessed either of these APIs via ws (not wss) and seen the problem?

I ask beacuse the use of wss and the message Control frame received with opcode 8 makes me wonder if this could be related to https://github.com/zaphoyd/websocketpp/issues/263

SatoshiReport commented 5 years ago

I tried testing these with ws instead of wss but these exchanges unfortunately don't offer a ws connection.

SatoshiReport commented 5 years ago

The issues could be related, I don't know, but the only commonality in the error messages is opcode 8.

alandipert commented 5 years ago

OK, thanks for looking into it. Yeah: the connection is tenuous. I'm tied up with something else at the moment but in the near future I'll investigate.

SatoshiReport commented 4 years ago

Thanks Alan!

alandipert commented 4 years ago

@wch reminded me to suggest to you to try the latest websocket from master as there have been some recent changes that might help (or might make it worse... but your feedback either way would be helpful 😄)

SatoshiReport commented 4 years ago

Thank you. I did a "install_github("rstudio/websocket") to get the latest code. I then tried the deribit.com example shown above and within 10 minutes I received the following (same) error:

[2020-01-29 17:50:25] [control] Control frame received with opcode 8
[2020-01-29 17:50:25] [frame_header] Dispatching write containing 1 message(s) 
containing 6 header bytes and 2 payload bytes
[2020-01-29 17:50:25] [frame_header] Header Bytes: 
[0] (6) 88 82 91 BF F1 BD 

[2020-01-29 17:50:25] [frame_payload] Payload Bytes: 
[0] (2) [8] 92 57 

[2020-01-29 17:50:25] [disconnect] Disconnect close local:[1000] remote:[1000]
[2020-01-29 17:50:25] [info] asio async_write error: asio.ssl:337690831 
(protocol is shutdown)
[2020-01-29 17:50:25] [fatal] handle_write_frame error: websocketpp.transport:2 
(Underlying Transport Error)
Error: Client disconnected with code  1000
SatoshiReport commented 4 years ago

I re-installed the latest production library and received the same error, so the recent updates did not seem to help.

nr0q commented 3 years ago

I am getting the same error here, may or may not be related. I haven't found a set amount of time for my connection to "time-out" as it seems and opcode 8 message and disconnect. Server is running node.JS and is handling 2,000 concurrent connections across 20 ports. Over half the clients are also running on node.js, I'm the only one using a program written in C++.

Here's the output of my program being run inside valgrind

[mchambers@nr0q-1 oamprs]$ valgrind ./oams.out 
==744820== Memcheck, a memory error detector
==744820== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==744820== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==744820== Command: ./oams.out
==744820== 
[2021-01-02 17:06:27] [application] Connecting to wss://tagloomis.com:18261
[2021-01-02 17:06:28] [connect] Successful connection
[2021-01-02 17:06:29] [connect] WebSocket Connection 104.197.59.209:18261 v-2 "WebSocket++/0.8.2" / 101
[2021-01-02 17:06:29] [application] Sent Message: {"call":"APRS","src":"AP","type":"uuid"}
[2021-01-02 17:06:29] [frame_header] Dispatching write containing 1 message(s) containing 6 header bytes and 40 payload bytes
[2021-01-02 17:06:29] [frame_header] Header Bytes: 
[0] (6) 81 A8 32 9A 22 73 

[2021-01-02 17:06:29] [application] Sent Message: {"band":"OOB","call":"APRS","canmsg":true,"freq":0,"grid":"EN21bf","id":120299,"mode":"PACKET","o":0,"type":"status","uuid":"Akjgbf6ts"}
[2021-01-02 17:06:29] [application] Sent Message: {"type":"list","uuid":"Akjgbf6ts"}
[2021-01-02 17:06:29] [frame_header] Dispatching write containing 2 message(s) containing 14 header bytes and 170 payload bytes
[2021-01-02 17:06:29] [frame_header] Header Bytes: 
[0] (8) 81 FE 00 88 D0 A7 4F 21 
[1] (6) 81 A2 29 B8 E5 37 

Found APRS in the list.
Message from: NR0Q
ID: 120211
CID: Akj7muprg
Message to: TEST
Messgae Text: this is a test message
[2021-01-02 17:06:57] [application] Sent Message: {"cid":"Akj7muprg","msg":"WW91ciBtZXNzYWdlIHRvIFRFU1Qgd2FzIHJlY2VpdmVkIGJ5IEFQUlMgYXQgMjAyMS0wMS0wMiAyMzowNjo1Ny4yNTYzOTc4OTMuIFRoZXJlIGlzIG5vIGFzc3VyYW5jZSB5b3VyIG1lc3NhZ2UgY2FuIGJlIGRlbGl2ZXJlZCBidXQgd2Ugd2lsbCBkbyBhIGJlc3QgZWZmb3J0IHRvLg==","type":"mesg","uuid":"Akjgbf6ts"}
[2021-01-02 17:06:57] [frame_header] Dispatching write containing 1 message(s) containing 8 header bytes and 277 payload bytes
[2021-01-02 17:06:57] [frame_header] Header Bytes: 
[0] (8) 81 FE 01 15 88 86 5A 45 

Message from: NR0Q
ID: 120211
CID: Akj7muprg
Message to: TEST
Messgae Text: hello, testing 1-2-3
[2021-01-02 17:07:23] [application] Sent Message: {"cid":"Akj7muprg","msg":"WW91ciBtZXNzYWdlIHRvIFRFU1Qgd2FzIHJlY2VpdmVkIGJ5IEFQUlMgYXQgMjAyMS0wMS0wMiAyMzowNzoyMy43NjI5MzIwMjIuIFRoZXJlIGlzIG5vIGFzc3VyYW5jZSB5b3VyIG1lc3NhZ2UgY2FuIGJlIGRlbGl2ZXJlZCBidXQgd2Ugd2lsbCBkbyBhIGJlc3QgZWZmb3J0IHRvLg==","type":"mesg","uuid":"Akjgbf6ts"}
[2021-01-02 17:07:23] [frame_header] Dispatching write containing 1 message(s) containing 8 header bytes and 277 payload bytes
[2021-01-02 17:07:23] [frame_header] Header Bytes: 
[0] (8) 81 FE 01 15 5A E2 CD B7 

[2021-01-02 17:16:34] [control] Control frame received with opcode 8
[2021-01-02 17:16:34] [frame_header] Dispatching write containing 1 message(s) containing 6 header bytes and 2 payload bytes
[2021-01-02 17:16:34] [frame_header] Header Bytes: 
[0] (6) 88 82 7A 5C FA 46 

[2021-01-02 17:16:39] [info] asio async_read_at_least error: asio.ssl.stream:1 (stream truncated)
[2021-01-02 17:16:39] [error] handle_read_frame error: websocketpp.transport:2 (Underlying Transport Error)
invalid state
==744820== 
==744820== HEAP SUMMARY:
==744820==     in use at exit: 2,074 bytes in 6 blocks
==744820==   total heap usage: 31,857 allocs, 31,851 frees, 15,166,743 bytes allocated
==744820== 
==744820== LEAK SUMMARY:
==744820==    definitely lost: 0 bytes in 0 blocks
==744820==    indirectly lost: 0 bytes in 0 blocks
==744820==      possibly lost: 320 bytes in 1 blocks
==744820==    still reachable: 1,754 bytes in 5 blocks
==744820==         suppressed: 0 bytes in 0 blocks
==744820== Rerun with --leak-check=full to see details of leaked memory
==744820== 
==744820== For lists of detected and suppressed errors, rerun with: -s
==744820== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
[mchambers@nr0q-1 oamprs]$
AlexIvanHoward commented 2 years ago

Has this issue been resolved in the meantime? I'm getting this error right now, the moment I try to connect to a websocket. It seems that already the very first message from the server causes the client to throw this error.

SatoshiReport commented 1 year ago

It has not been resolved. I looked at the R code and it is a pass through to the corresponding c/c++ library. I suspect the issue is there but I have not been able to prove it yet.