Skip to content

minor: v2.10.0#762

Merged
panjf2000 merged 2 commits into
masterfrom
dev
Jul 3, 2026
Merged

minor: v2.10.0#762
panjf2000 merged 2 commits into
masterfrom
dev

Conversation

@panjf2000

Copy link
Copy Markdown
Owner

No description provided.

panjf2000 and others added 2 commits July 2, 2026 22:08
The pinned golangci-lint v2.1.6 (built with Go 1.24) panics when
analyzing code with the Go 1.26 toolchain installed by setup-go,
since go/types refuses to type-check files requiring a newer Go
version than the one golangci-lint itself was built with:

  panic: file requires newer Go version go1.26 (application built with go1.24)

Bumped all 4 workflow files that pin golangci-lint (test.yml,
test_gc_opt.yml, test_poll_opt.yml, test_poll_opt_gc_opt.yml) to
v2.12.2, which is built with Go 1.26.2.

Verified locally: golangci-lint v2.12.2 run with the same linters/args
as CI (-E gocritic -E misspell -E revive -E godot, with/without
--timeout 5m) reports 0 issues on the repo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…fined context (#760)

Add SafeContext() and SetSafeContext(ctx any) to the Conn interface,
backed by atomic.Pointer[any], allowing goroutines other than the
owning event-loop to safely read/write a connection's user-defined
context without racing against Context()/SetContext(), which remain
event-loop-only.

- Implement safeCtx atomic.Pointer[any] field and accessors in
  connection_unix.go/connection_windows.go; wire up initial context on
  Windows via SetSafeContext at connection construction; reset safeCtx
  to nil in release().
- Clarify Conn interface doc comments for SafeContext/SetSafeContext
  (reference Context/SetContext directly) and for LocalAddr/RemoteAddr
  (note callers must copy the returned net.Addr via String() if used
  outside EventHandler).
- Add TestSafeContext (gnet_test.go) and TestClientSafeContext
  (client_test.go) covering: nil before first SetSafeContext, rotating
  concrete types (including nil) via OnTraffic, concurrent SafeContext
  reads from a background goroutine, no interference with
  Context()/SetContext(), correctness immediately after Dial/OnOpen,
  safety when called from OnClose, and reset to nil after release().
- Avoid port 10000 in existing tests (conflicts with a common local
  service on some machines), switching to 19999.

---------

Co-authored-by: Andy Pan <i@andypan.me>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 13:14
@github-actions github-actions Bot added minor Release minor version new feature labels Jul 3, 2026
@panjf2000 panjf2000 added enhancement New feature or request docs labels Jul 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a concurrency-safe connection context API (SafeContext / SetSafeContext) across the core Conn implementations, adds coverage to validate the new contract (including cross-goroutine access and type mixing), and updates CI linting to a newer golangci-lint release.

Changes:

  • Extend Conn with SafeContext() / SetSafeContext(any) and clarify LocalAddr/RemoteAddr concurrency notes.
  • Implement safeCtx storage using atomics in Unix/Windows connection implementations and initialize it for enrolled/client connections.
  • Add server/client tests for SafeContext behavior and bump several hardcoded test ports; update GitHub Actions lint workflows to golangci-lint v2.12.2.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
gnet.go Adds SafeContext/SetSafeContext to the public Conn interface and updates address concurrency documentation.
eventloop_unix.go Ensures enrolled connections have both Context and SafeContext initialized from enrollment ctx.
client_unix.go Ensures client-enrolled connections have both Context and SafeContext initialized from dial/enroll ctx.
connection_unix.go Adds atomic-backed safeCtx field and implements SafeContext/SetSafeContext; clears on release().
connection_windows.go Adds atomic-backed safeCtx field, initializes it in constructors, implements SafeContext/SetSafeContext, clears on release().
gnet_test.go Updates some fixed ports and adds a TestSafeContext validating concurrency-safe behavior.
client_test.go Adds TestClientSafeContext validating dial-time ctx propagation and concurrency-safe behavior.
.github/workflows/test.yml Bumps golangci-lint version used by the lint job.
.github/workflows/test_poll_opt.yml Bumps golangci-lint version used by the lint job.
.github/workflows/test_poll_opt_gc_opt.yml Bumps golangci-lint version used by the lint job.
.github/workflows/test_gc_opt.yml Bumps golangci-lint version used by the lint job.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gnet.go
Comment on lines +433 to +436
// SafeContext is the concurrency-safe version of Context that can
// be invoked on any goroutine.
SafeContext() (ctx any)

Comment thread gnet_test.go
Comment on lines +2789 to +2808
err := goPool.DefaultWorkerPool.Submit(func() {
for {
select {
case <-s.stopBackground:
return
default:
}
switch v := c.SafeContext().(type) {
case nil:
case *safeCtxPayloadA:
_ = v.n
case *safeCtxPayloadB:
_ = v.s
case int:
default:
assert.Failf(s.tester, "unexpected SafeContext type", "%T", v)
}
atomic.AddInt32(&s.backgroundHits, 1)
}
})
Comment thread client_test.go
Comment on lines +887 to +906
err := goPool.DefaultWorkerPool.Submit(func() {
for {
select {
case <-ev.stopBackground:
return
default:
}
switch v := c.SafeContext().(type) {
case nil:
case *safeCtxPayloadA:
_ = v.n
case *safeCtxPayloadB:
_ = v.s
case int:
default:
assert.Failf(ev.tester, "unexpected SafeContext type", "%T", v)
}
atomic.AddInt32(&ev.backgroundHits, 1)
}
})
Comment on lines 49 to 53
- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.1.6
version: v2.12.2
args: -v -E gocritic -E misspell -E revive -E godot --timeout 5m
Comment on lines 48 to 52
- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.1.6
version: v2.12.2
args: -v -E gocritic -E misspell -E revive -E godot
Comment on lines 48 to 52
- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.1.6
version: v2.12.2
args: -v -E gocritic -E misspell -E revive -E godot
Comment on lines 49 to 53
- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.1.6
version: v2.12.2
args: -v -E gocritic -E misspell -E revive -E godot --timeout 5m
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.80%. Comparing base (fd7ce4b) to head (441457f).
⚠️ Report is 37 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #762      +/-   ##
==========================================
+ Coverage   84.38%   84.80%   +0.41%     
==========================================
  Files          22       22              
  Lines        2402     2422      +20     
==========================================
+ Hits         2027     2054      +27     
+ Misses        255      252       -3     
+ Partials      120      116       -4     
Flag Coverage Δ
unittests 84.80% <100.00%> (+0.41%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@panjf2000
panjf2000 merged commit 58b59a1 into master Jul 3, 2026
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs enhancement New feature or request minor Release minor version new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants