Skip to content

Conversation

@gunli
Copy link
Contributor

@gunli gunli commented Dec 25, 2025

1. Are you opening this pull request for bug-fix, optimization or new feature?

This PR is for bug-fix.
Currently, the Unix client fd will leak to the child process, because we call unix.Dup(int(fd))--which will remove the FD_CLOEXEC flag--to duplicate the raw fd, and that is unsafe.

	var dupFD int
	e := rc.Control(func(fd uintptr) {
		dupFD, err = unix.Dup(int(fd))	
	})

2. Please describe how these code changes achieve your intention.

// EnrollContext is like Enroll but also accepts an empty interface ctx that can be obtained later via Conn.Context.
func (cli *Client) EnrollContext(c net.Conn, ctx any) (Conn, error) {
	// ......
	var dupFD int
	e := rc.Control(func(fd uintptr) {
		dupFD, err = unix.Dup(int(fd))
		// Set the socket to close-on-exec, so that the socket is closed when the process forks
		unix.CloseOnExec(dupFD)
	})
	// ...... 
}

3. Please link to the relevant issues (if any).

4. What documentation changes (if any) need to be made/updated because of this PR?

4. Checklist

  • I have squashed all insignificant commits.
  • I have commented my code for explaining package types, values, functions, and non-obvious lines.
  • I have written unit tests and verified that all tests passes (if needed).
  • I have documented feature info on the README (only when this PR is adding a new feature).
  • (optional) I am willing to help maintain this change if there are issues with it later.

@panjf2000 panjf2000 self-assigned this Dec 25, 2025
@panjf2000 panjf2000 added bug Something isn't working enhancement New feature or request labels Dec 25, 2025
@codecov
Copy link

codecov bot commented Dec 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.31%. Comparing base (a46e1e7) to head (969c4b4).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #743   +/-   ##
=======================================
  Coverage   84.30%   84.31%           
=======================================
  Files          22       22           
  Lines        2402     2403    +1     
=======================================
+ Hits         2025     2026    +1     
  Misses        257      257           
  Partials      120      120           
Flag Coverage Δ
unittests 84.31% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Owner

@panjf2000 panjf2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@panjf2000 panjf2000 merged commit 58d255f into panjf2000:dev Dec 25, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants