Skip to content

fix(context): data race#4660

Open
0xff-dev wants to merge 1 commit into
gin-gonic:masterfrom
0xff-dev:ctx-data-race
Open

fix(context): data race#4660
0xff-dev wants to merge 1 commit into
gin-gonic:masterfrom
0xff-dev:ctx-data-race

Conversation

@0xff-dev
Copy link
Copy Markdown

Pull Request Checklist

fix(context): data race

package main

import (
	"sync"

	"github.com/gin-gonic/gin"
)

func main() {
	e := gin.Default()
	e.GET("/hello", func(ctx *gin.Context) {
		var wg sync.WaitGroup
		const n = 20

		wg.Add(1)
		go func() {
			defer wg.Done()
			for i := 0; i < n; i++ {
				ctx.Set("key", i)
			}
		}()
		wg.Add(1)
		go func() {
			defer wg.Done()
			for i := 0; i < n; i++ {
				_ = ctx.Copy()
			}
		}()
		wg.Wait()
		_, _ = ctx.Writer.Write([]byte("done"))
	})

	e.Run(":8098")
}

run

go run -race main.go

test

curl http://127.0.0.1:8098/hello

outout

==================
WARNING: DATA RACE
Write at 0x00c0001fc280 by goroutine 10:

Please ensure your pull request meets the following requirements:

  • Open your pull request against the master branch.
  • All tests pass in available continuous integration systems (e.g., GitHub Actions).
  • Tests are added or modified as needed to cover code changes.
  • If the pull request introduces a new feature, the feature is documented in the docs/doc.md.

Thank you for contributing!

Signed-off-by: 0xff-dev <stevenshuang521@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.37%. Comparing base (3dc1cd6) to head (34ff4d8).
⚠️ Report is 276 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4660      +/-   ##
==========================================
- Coverage   99.21%   98.37%   -0.85%     
==========================================
  Files          42       48       +6     
  Lines        3182     3137      -45     
==========================================
- Hits         3157     3086      -71     
- Misses         17       42      +25     
- Partials        8        9       +1     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.36% <100.00%> (?)
-tags go_json 98.29% <100.00%> (?)
-tags nomsgpack 98.35% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.25 98.37% <100.00%> (?)
go-1.26 98.37% <100.00%> (?)
macos-latest 98.37% <100.00%> (-0.85%) ⬇️
ubuntu-latest 98.37% <100.00%> (-0.85%) ⬇️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant