Closed titilami closed 4 years ago
@titilami thanks for the feedback, I had a look the source code of websocket and I think we can find a solution. I will do more test and fix this.
@eynzhang thx, i have multi goroutines to send websocket request. These goroutines may call WebSocketClientBase.conn.WriteMessage simultaneous at sometime .
@titilami I think we need to handle it ourselves in SDK, the gorilla websocket doesn’t support concurrent write message, see below words from their documentation:
https://github.com/gorilla/websocket/blob/master/doc.go
Concurrency
Connections support one concurrent reader and one concurrent writer.
Applications are responsible for ensuring that no more than one goroutine
calls the write methods (NextWriter, SetWriteDeadline, WriteMessage,
WriteJSON, EnableWriteCompression, SetCompressionLevel) concurrently and
that no more than one goroutine calls the read methods (NextReader,
SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler)
concurrently.
The Close and WriteControl methods can be called concurrently with all other
methods.
@titilami please get the lates update from master branch, the mutex is introduced to support concurrently subscribing. I tested it and it works well. You can refer to the new added traderexample.
@eynzhang thx.
i subscribe websocket market data and receive realtime kline,
Client.Subscribe("btcusdt", "1min", "2118")
. i also obtain historical kline periodically by a time.ticker goroutine,Client.Request(xxxxxxx)
but i got a panic finally after running a period of time,i think the reason is time.Ticker goroutine and ping pong in "startReadLoop --> readLoop" write websocket simultaneous, how to solve it?