-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
解决websocket并发 bug #73
Conversation
panic: concurrent write to websocket connection
WARNING: DATA RACE
WARNING: DATA RACE
WARNING: DATA RACE
代码里面有createWsLock 这个锁,应该不会出现并发问题哦 |
你可以试试,使用-race 编译试试, 会提示 WARNING: DATA RACE 至于,panic: concurrent write to websocket connection 低概率会发生,大概允许给你4,5个小时会导致程序直接崩溃 官方对此的解释 |
这个跟使用场景有关系,一般是启动策略后先发订阅信息,然后读取推送数据,这样就不存在并发了吧 |
我目前好像没遇到过并发问题,我在策略中已经实盘跑了okex websocket几个月了 |
我晚上回家把我的那个业务代码发给你看下吧,同时连接的 okex和火币 -race 编译运行 会出现WARNING: DATA RACE的错误 |
1. 源代码package main
import (
"github.com/nntaoli-project/GoEx/huobi"
"github.com/nntaoli-project/GoEx"
"net/http"
"fmt"
)
func main() {
var huoBiPro = huobi.NewHuoBiProSpot(http.DefaultClient, "", "")
huoBiPro.GetTickerWithWs(goex.EOS_USDT, func(ticker *goex.Ticker) {
fmt.Printf("huobi \n")
})
select {
}
} 2. 编译运行go run -race main.go
3. 错误警告
|
又增加了okex的新版websocket支持 |
解决2个并发问题