Skip to content

Commit

Permalink
fix: fd operator read race after inuse called (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
joway authored Jul 24, 2024
1 parent c570ed6 commit c8fc8e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion poll_default_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func (p *defaultPoll) Trigger() error {

// Control implements Poll.
func (p *defaultPoll) Control(operator *FDOperator, event PollEvent) error {
// DON'T move `fd=operator.FD` behind inuse() call, we can only access operator before op.inuse() for avoid race
// G1: G2:
// op.inuse() op.unused()
// op.FD -- T1 op.FD = 0 -- T2
// T1 and T2 may happen together
var fd = operator.FD
var op int
var evt epollevent
p.setOperator(unsafe.Pointer(&evt.data), operator)
Expand All @@ -256,5 +262,5 @@ func (p *defaultPoll) Control(operator *FDOperator, event PollEvent) error {
case PollRW2R: // connection wait read
op, evt.events = syscall.EPOLL_CTL_MOD, syscall.EPOLLIN|syscall.EPOLLRDHUP|syscall.EPOLLERR
}
return EpollCtl(p.fd, op, operator.FD, &evt)
return EpollCtl(p.fd, op, fd, &evt)
}

0 comments on commit c8fc8e5

Please sign in to comment.