ThinkingDataAnalytics / go-sdk

ThinkingData SDK for Golang
Apache License 2.0
9 stars 13 forks source link

停服调用close后 导致panic #11

Open lqxhub opened 1 year ago

lqxhub commented 1 year ago

在游戏停服时, 在main函数里 使用defer 调用 TDAnalytics::Close 函数,但是在log里发现有 panic 发生,最终定位到是这行 https://github.com/ThinkingDataAnalytics/go-sdk/blob/81f51ce77d2fcecbc4b3ce78b2cf0bc62dfa41cb/thinkingdata/consumer_log.go#L84

往一个close的channel里写数据导致的panic

github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*LogConsumer).Add(0xc0000bb8c0, {{0xc0006220c8, 0x7}, {0x0, 0x0}, {0x2aa5e2f, 0x5}, {0xc0009e0048, 0x17}, {0x2aa64ce, ...}, ...})
       ......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_log.go:84 +0xb1
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).add(0x46ed720, {0xc0006220c8, 0x7}, {0x0, 0x0}, {0x2aa5e2f, 0x5}, {0x2aa64ce, 0x6}, {0x0, ...}, ...)
        ......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:246 +0x33b
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).track(0xc001068000, {0xc0006220c8, 0x7}, {0x0, 0x0}, {0x2aa5e2f, 0x5}, {0x2aa64ce, 0xc00013f530}, {0x0, ...}, ...)
       ......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:144 +0x21e
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).Track(0x263fde0, {0xc0006220c8, 0x2aa5c45}, {0x0, 0xc0012e77a0}, {0x2aa64ce, 0xc0012e77e0}, 0xc0012e7800)
       ......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:103 +0x4b

所以这里是不是要加一个 判断,如果channel已经关闭了,后续在有数据进来 直接丢掉,或者加一些同步机制,保证不会出现提前close的情况