Skip to content

Commit 67ff775

Browse files
committed
fix recover call missing without defer. check some nil deref.
1 parent 75869fa commit 67ff775

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

scouterx/common/netdata/step.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ func StepsToBytes(steps []Step) []byte {
8484
}
8585
dout := NewDataOutputX(nil)
8686
for _, step := range steps {
87-
dout.WriteStep(step)
87+
if step != nil {
88+
dout.WriteStep(step)
89+
}
8890
}
8991
return dout.Bytes()
9092
}

scouterx/strace/tracemain.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func StartTracingMode() {
2727
}
2828

2929
func IsStream(ctx context.Context) bool {
30-
common.ReportScouterPanic()
30+
defer common.ReportScouterPanic()
3131
if ctx == nil {
3232
return false
3333
}
@@ -39,7 +39,7 @@ func IsStream(ctx context.Context) bool {
3939
}
4040

4141
func SetAsStream(ctx context.Context) bool {
42-
common.ReportScouterPanic()
42+
defer common.ReportScouterPanic()
4343
if ctx == nil {
4444
return false
4545
}
@@ -52,7 +52,7 @@ func SetAsStream(ctx context.Context) bool {
5252
}
5353

5454
func MarkAsError(ctx context.Context, errorMessage string) {
55-
common.ReportScouterPanic()
55+
defer common.ReportScouterPanic()
5656
if ctx == nil {
5757
return
5858
}
@@ -67,7 +67,7 @@ func MarkAsError(ctx context.Context, errorMessage string) {
6767
}
6868

6969
func MarkAsErrorForcibly(ctx context.Context, errorMessage string) {
70-
common.ReportScouterPanic()
70+
defer common.ReportScouterPanic()
7171
if ctx == nil {
7272
return
7373
}
@@ -79,7 +79,7 @@ func MarkAsErrorForcibly(ctx context.Context, errorMessage string) {
7979
}
8080

8181
func SetServiceNameForcibly(ctx context.Context, serviceName string) {
82-
common.ReportScouterPanic()
82+
defer common.ReportScouterPanic()
8383
if ctx == nil {
8484
return
8585
}
@@ -192,7 +192,7 @@ func normalizeIp(ip string) string {
192192
}
193193

194194
func EndHttpService(ctx context.Context, req *http.Request, res *http.Response) {
195-
common.ReportScouterPanic()
195+
defer common.ReportScouterPanic()
196196
//TODO body (of specific service) profile from req.body
197197

198198
if res != nil {
@@ -209,7 +209,7 @@ func EndHttpService(ctx context.Context, req *http.Request, res *http.Response)
209209
}
210210

211211
func StartService(ctx context.Context, serviceName, remoteIp string) (newCtx context.Context) {
212-
common.ReportScouterPanic()
212+
defer common.ReportScouterPanic()
213213
if ctx == nil {
214214
ctx = context.Background()
215215
}
@@ -223,13 +223,13 @@ func StartService(ctx context.Context, serviceName, remoteIp string) (newCtx con
223223
}
224224

225225
func EndService(ctx context.Context) {
226-
common.ReportScouterPanic()
226+
defer common.ReportScouterPanic()
227227
endAnyService(ctx)
228228
}
229229

230230
func StartNewInheritanceService(ctx context.Context, parentTctx *netio.TraceContext) (newCtx context.Context, newTctx *netio.TraceContext) {
231231
//TODO ctx를 전달받지 않아야 될 것 같긴한데...
232-
common.ReportScouterPanic()
232+
defer common.ReportScouterPanic()
233233
if ctx == nil {
234234
ctx = context.Background()
235235
}
@@ -287,7 +287,7 @@ func inheritTctx(newTctx *netio.TraceContext, parentTctx *netio.TraceContext) *n
287287
// myFunc(cascadeGoCtx)
288288
//})
289289
func GoWithTrace(ctx context.Context, serviceName string, func4Goroutine func(cascadeGoCtx context.Context)) {
290-
common.ReportScouterPanic()
290+
defer common.ReportScouterPanic()
291291
newCtx, childTctx := startChildGoroutineService(ctx, serviceName)
292292
go func() {
293293
if childTctx != nil {
@@ -326,7 +326,7 @@ func startChildGoroutineService(ctx context.Context, serviceName string) (ctx4Go
326326
}
327327

328328
func endChildGoroutineService(ctx context.Context) {
329-
common.ReportScouterPanic()
329+
defer common.ReportScouterPanic()
330330
endAnyService(ctx)
331331
}
332332

0 commit comments

Comments
 (0)