Skip to content
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

数据竞争bug #26

Closed
jinsuojinsuo opened this issue Nov 24, 2022 · 6 comments · Fixed by #29
Closed

数据竞争bug #26

jinsuojinsuo opened this issue Nov 24, 2022 · 6 comments · Fixed by #29
Labels
bug Something isn't working

Comments

@jinsuojinsuo
Copy link

Dcron.Start() //启动分布式定时任务
Dcron.Stop()//停止定时任务

会产生数据竞争

代码
`
//分布式定时任务路由
Dcron.Start() //启动分布式定时任务

quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
sign := <-quit //阻塞等待结束信号
utils.Logger().Info().Msgf("%v %v %v %+v", "SERVER_RUN", "server_close_sig", "", sign)

//停止定时任务
Dcron.Stop()

==================
WARNING: DATA RACE
Read at 0x00c000594038 by goroutine 46:
github.com/libi/dcron.(*NodePool).tickerUpdatePool()
C:/Users/yunwe/go/pkg/mod/github.com/libi/dcron@v0.2.2/node_pool.go:77 +0xfb
github.com/libi/dcron.(*NodePool).StartPool.func1()
C:/Users/yunwe/go/pkg/mod/github.com/libi/dcron@v0.2.2/node_pool.go:57 +0x39

Previous write at 0x00c000594038 by main goroutine:
github.com/libi/dcron.(*Dcron).Stop()
C:/Users/yunwe/go/pkg/mod/github.com/libi/dcron@v0.2.2/dcron.go:159 +0x39
main.main()
D:/code_qifan/jump_live/main.go:81 +0x486

Goroutine 46 (running) created at:
github.com/libi/dcron.(*NodePool).StartPool()
C:/Users/yunwe/go/pkg/mod/github.com/libi/dcron@v0.2.2/node_pool.go:57 +0x1e5
github.com/libi/dcron.(*Dcron).Start()
C:/Users/yunwe/go/pkg/mod/github.com/libi/dcron@v0.2.2/dcron.go:134 +0x84
main.main()
D:/code_qifan/jump_live/main.go:69 +0x271

`

@libi libi added the bug Something isn't working label Dec 1, 2022
@libi
Copy link
Owner

libi commented Dec 1, 2022

启动定时任务后立刻关闭产生的的竞争吧?

@jinsuojinsuo
Copy link
Author

这问题 不是立即关闭也会产生,如果有秒级别的定时任务 func (np *NodePool) tickerUpdatePool() 函数中的 for循环 频繁扫描 np.dcron.isRun,也很容易产生

@libi libi linked a pull request Dec 1, 2022 that will close this issue
@libi
Copy link
Owner

libi commented Dec 1, 2022

这问题 不是立即关闭也会产生,如果有秒级别的定时任务 func (np *NodePool) tickerUpdatePool() 函数中的 for循环 频繁扫描 np.dcron.isRun,也很容易产生
轮训的时候只是读取,没有写入操作也不会产生竞争,不过频繁关闭启动的场景也确实需要修复。

@libi libi closed this as completed in #29 Dec 1, 2022
libi added a commit that referenced this issue Dec 1, 2022
#26 fix start/stop dcron data race
@libi
Copy link
Owner

libi commented Dec 1, 2022

@jinsuojinsuo 修复了 还没打tag ,你直接在 go.mod 里声明版本为 master 就可以用了。

@jinsuojinsuo
Copy link
Author

好的感谢

@jinsuojinsuo
Copy link
Author

轮训的时候只是读取,没有写入操作也不会产生竞争,不过频繁关闭启动的场景也确实需要修复。
两个读不产生竞争,一读一写也会产生竞争,两个写也会产生竞争,所以我理解轮训读 哪也会与 写产生竞争

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants