Skip to content

Commit

Permalink
opt: use runtimex to avoid panic (#9)
Browse files Browse the repository at this point in the history
* opt: use `unsafe.Add` to avoid race panic

* udpate

* update
  • Loading branch information
AsterDY authored Jan 10, 2025
1 parent bfce75f commit 3936e3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
module github.com/cloudwego/localsession

go 1.16
go 1.17

require (
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/cloudwego/runtimex v0.1.1
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b h1:R6PWoQtxEMpWJPHnpci+9LgFxCS7iJCfOGBvCgZeTKI=
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ=
github.com/cloudwego/runtimex v0.1.1 h1:lheZjFOyKpsq8TsGGfmX9/4O7F0TKpWmB8on83k7GE8=
github.com/cloudwego/runtimex v0.1.1/go.mod h1:23vL/HGV0W8nSCHbe084AgEBdDV4rvXenEUMnUNvUd8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5 h1:uiS4zKYKJVj5F3ID+5iylfKPsEQmBEOucSD9Vgmn0i0=
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5/go.mod h1:I8AX+yW//L8Hshx6+a1m3bYkwXkpsVjA2795vP4f4oQ=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
12 changes: 8 additions & 4 deletions stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ import (
"strconv"
_ "unsafe"

"github.com/modern-go/gls"
"github.com/cloudwego/runtimex"
)

//go:nocheckptr
func goID() uint64 {
return uint64(gls.GoID())
gid, err := runtimex.GID()
if err != nil {
panic(err)
}
return uint64(gid)
}

type labelMap map[string]string
Expand All @@ -49,7 +53,7 @@ func transmitSessionID(id SessionID) {
}
}
}

n[Pprof_Label_Session_ID] = strconv.FormatInt(int64(id), 10)
setPprofLabel(&n)
}
Expand All @@ -73,7 +77,7 @@ func getSessionID() (SessionID, bool) {
func clearSessionID() {
m := getPproLabel()
if m == nil {
return
return
}
if _, ok := (*m)[Pprof_Label_Session_ID]; !ok {
return
Expand Down

0 comments on commit 3936e3c

Please sign in to comment.