cloudwego / netpoll

A high-performance non-blocking I/O networking framework focusing on RPC scenarios.
Apache License 2.0
4.07k stars 470 forks source link

fix: fd operator read race after inuse called #351

Closed joway closed 4 months ago

joway commented 4 months ago

What type of PR is this?

fix

Check the PR title.

(Optional) Translate the PR title into Chinese.

fix: 修复 fd operator 在 inuse 调用后的读竞争问题

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en: zh(optional):

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

joway commented 4 months ago

fix race stack like this:

refactor: deprecate bthrift, use cloudwego/gopkg · cloudwego/kitex@707b494](https://github.com/cloudwego/kitex/actions/runs/10071020352/job/27840467863?pr=1441)
==================
52WARNING: DATA RACE
53Write at 0x00c0001d9650 by goroutine 51:
54  github.com/cloudwego/netpoll.(*FDOperator).reset()
55      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/fd_operator.go:96 +0x64
56  github.com/cloudwego/netpoll.(*operatorCache).freeable()
57      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/fd_operator_cache.go:68 +0x5c
58  github.com/cloudwego/netpoll.(*defaultPoll).Free()
59      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_default.go:27 +0x53
60  github.com/cloudwego/netpoll.(*FDOperator).Free()
61      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/fd_operator.go:62 +0x8b
62  github.com/cloudwego/netpoll.(*connection).initFinalizer.func1()
63      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/connection_impl.go:382 +0x46
64  github.com/cloudwego/netpoll.(*connection).closeCallback()
65      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/connection_onevent.go:321 +0x288
66  github.com/cloudwego/netpoll.(*connection).onHup()
67      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/connection_reactor.go:45 +0x195
68  github.com/cloudwego/netpoll.(*connection).onHup-fm()
69      <autogenerated>:1 +0x4d
70  github.com/cloudwego/netpoll.(*defaultPoll).onhups.func1()
71      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_default.go:51 +0xa9
72  github.com/cloudwego/netpoll.(*defaultPoll).onhups.func2()
73      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_default.go:54 +0x66
74
75Previous read at 0x00c0001d9650 by goroutine 50:
76  github.com/cloudwego/netpoll.(*defaultPoll).Control()
77      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_default_linux.go:259 +0x1e4
78  github.com/cloudwego/netpoll.(*FDOperator).Control()
79      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/fd_operator.go:58 +0x81
80  github.com/cloudwego/netpoll.(*connection).register()
81      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/connection_onevent.go:328 +0x52
82  github.com/cloudwego/netpoll.(*connection).onPrepare()
83      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/connection_onevent.go:128 +0x2b5
84  github.com/cloudwego/netpoll.(*connection).init()
85      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/connection_impl.go:354 +0x486
86  github.com/cloudwego/netpoll.(*server).onAccept()
87      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/netpoll_server.go:160 +0x71
88  github.com/cloudwego/netpoll.(*server).OnRead()
89      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/netpoll_server.go:98 +0x34e
90  github.com/cloudwego/netpoll.(*server).OnRead-fm()
91      <autogenerated>:1 +0x4d
92  github.com/cloudwego/netpoll.(*defaultPoll).handler()
93      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_default_linux.go:153 +0x1e9
94  github.com/cloudwego/netpoll.(*defaultPoll).handler-fm()
95      <autogenerated>:1 +0x57
96  github.com/cloudwego/netpoll.(*defaultPoll).Wait()
97      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_default_linux.go:110 +0x227
98  github.com/cloudwego/netpoll.(*manager).Run.func2()
99      /root/go/pkg/mod/github.com/cloudwego/netpoll@v0.6.2/poll_manager.go:140 +0x48