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

fix: fd operator segment fault because not being cached #360

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions net_netfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func (c *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysca
}

c.pd = newPollDesc(c.fd)
defer func() {
// free operator to avoid leak
c.pd.operator.Free()
c.pd = nil
}()
for {
// Performing multiple connect system calls on a
// non-blocking socket under Unix variants does not
Expand Down
14 changes: 5 additions & 9 deletions net_polldesc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
func newPollDesc(fd int) *pollDesc {
pd := &pollDesc{}
poll := pollmanager.Pick()
pd.operator = &FDOperator{
poll: poll,
FD: fd,
OnWrite: pd.onwrite,
OnHup: pd.onhup,
}
pd.operator = poll.Alloc()
pd.operator.poll = poll
pd.operator.FD = fd
pd.operator.OnWrite = pd.onwrite
pd.operator.OnHup = pd.onhup
pd.writeTrigger = make(chan struct{})
pd.closeTrigger = make(chan struct{})
return pd
Expand Down Expand Up @@ -60,10 +59,7 @@ func (pd *pollDesc) WaitWrite(ctx context.Context) (err error) {
err = nil
case <-ctx.Done(): // triggered by ctx
// deregister from poller, upper caller function will close fd
// detach first but there's a very small possibility that operator is doing in poller,
// so need call unused() to wait operator done
pd.detach()
pd.operator.unused()
err = mapErr(ctx.Err())
}
// double check close trigger
Expand Down
Loading