Skip to content

Commit fec9612

Browse files
fix: segfault on Takesnapshot when go build -race (#252)
* fix: segfault on Takesnapshot when go build -race * update exetension readme and fix tracecontext * update fasthttp version --------- Co-authored-by: zhb192729 <[email protected]>
1 parent d71d610 commit fec9612

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

example/extension/nethttp/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Replace the `Path` in `config.json` with the actual absolute path of `rules` dir
1111
"OnEnter":"httpClientEnterHook",
1212
"ReceiverType": "*Transport",
1313
"OnExit": "httpClientExitHook",
14-
"Path": "/Users/zhanghaibin/Desktop/opentelemetry-go-auto-instrumentation/example/extension/nethttp/rules"
14+
"Path": "/path/opentelemetry-go-auto-instrumentation/example/extension/nethttp/rules"
1515
}]
1616
```
1717

1818
## Step2: Compile the target binary with otel
1919
Use `otel` to build the binary with `config.json`:
2020
```
21-
cd example/extension/netHttp
21+
cd example/extension/nethttp
22+
../../../otel set -rule=config.json
2223
../../../otel -rule=config.json go build demo/net_http.go
2324
```
2425
Users can get the `otel` according to [documentation](../../../README.md)

example/extension/nethttp/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"OnEnter":"httpClientEnterHook",
66
"ReceiverType": "*Transport",
77
"OnExit": "httpClientExitHook",
8-
"Path": "/path/to/nethttp/rules"
8+
"Path": "/path/opentelemetry-go-auto-instrumentation/example/extension/nethttp/rules"
99
}
1010
]

example/extension/sqlinject/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Replace the `Path` in `config.json` with the actual absolute path of `rules` dir
1818
Use `otel` to build the binary with `config.json`:
1919
```
2020
cd example/extension/sqlinject
21-
../../../otel -rule=config.json go build demo/sql_inject.go
21+
../../../otel set -rule=config.json
22+
../../../otel go build demo/sql_inject.go
2223
```
2324
Users can get the `otel` according to [documentation](../../../README.md)
2425

pkg/data/default.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@
521521
"Path": "github.com/alibaba/opentelemetry-go-auto-instrumentation/pkg/rules/hertz/client"
522522
},
523523
{
524-
"Version": "[1.45.0,1.57.1)",
524+
"Version": "[1.45.0,1.58.1)",
525525
"ImportPath": "github.com/valyala/fasthttp",
526526
"Function": "Do",
527527
"ReceiverType": "*HostClient",
@@ -530,7 +530,7 @@
530530
"Path": "github.com/alibaba/opentelemetry-go-auto-instrumentation/pkg/rules/fasthttp"
531531
},
532532
{
533-
"Version": "[1.45.0,1.57.1)",
533+
"Version": "[1.45.0,1.58.1)",
534534
"ImportPath": "github.com/valyala/fasthttp",
535535
"Function": "ListenAndServe",
536536
"ReceiverType": "*Server",

pkg/rules/otel-sdk/otel_baggage_util.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type BaggageContainer struct {
1818
baggage interface{}
1919
}
2020

21+
//go:norace
2122
func (bc *BaggageContainer) TakeSnapShot() interface{} {
2223
return &BaggageContainer{bc.baggage}
2324
}

pkg/rules/otel-sdk/trace-context/otel_trace_context.go

+13-19
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323
const maxSpans = 300
2424

2525
type traceContext struct {
26-
sw *spanWrapper
27-
n int
28-
Data map[string]interface{}
29-
lcs trace.Span
26+
sw *spanWrapper
27+
n int
28+
lcs trace.Span
3029
}
3130

3231
type spanWrapper struct {
@@ -54,6 +53,7 @@ func (tc *traceContext) add(span trace.Span) bool {
5453
return true
5554
}
5655

56+
//go:norace
5757
func (tc *traceContext) tail() trace.Span {
5858
if tc.n == 0 {
5959
return nil
@@ -92,43 +92,37 @@ func (tc *traceContext) del(span trace.Span) {
9292
func (tc *traceContext) clear() {
9393
tc.sw = nil
9494
tc.n = 0
95-
tc.Data = nil
9695
SetBaggageContainerToGLS(nil)
9796
}
9897

98+
//go:norace
9999
func (tc *traceContext) TakeSnapShot() interface{} {
100100
// take a deep copy to avoid reading & writing the same map at the same time
101-
var dataCopy = make(map[string]interface{})
102-
for key, value := range tc.Data {
103-
dataCopy[key] = value
104-
}
105101
if tc.n == 0 {
106-
return &traceContext{nil, 0, dataCopy, nil}
102+
return &traceContext{nil, 0, nil}
107103
}
108104
last := tc.tail()
109105
sw := &spanWrapper{last, nil}
110-
return &traceContext{sw, 1, dataCopy, nil}
106+
return &traceContext{sw, 1, nil}
111107
}
112108

113109
func GetGLocalData(key string) interface{} {
114-
t := getOrInitTraceContext()
115-
r := t.Data[key]
116-
return r
110+
//todo set key into traceContext struct
111+
//t := getOrInitTraceContext()
112+
113+
return nil
117114
}
118115

119116
func SetGLocalData(key string, value interface{}) {
120117
t := getOrInitTraceContext()
121-
if t.Data == nil {
122-
t.Data = make(map[string]interface{})
123-
}
124-
t.Data[key] = value
118+
125119
setTraceContext(t)
126120
}
127121

128122
func getOrInitTraceContext() *traceContext {
129123
tc := GetTraceContextFromGLS()
130124
if tc == nil {
131-
newTc := &traceContext{nil, 0, nil, nil}
125+
newTc := &traceContext{nil, 0, nil}
132126
setTraceContext(newTc)
133127
return newTc
134128
} else {

0 commit comments

Comments
 (0)