Skip to content

Commit ecabcf9

Browse files
authored
ignores: Don't use strings.Contains (#112)
Instead of matching for built-in functions with strings.Contains, use the parsed stack information to match function names exactly. Following this change, the only remaining strings.Contains are to match on the goroutine state: ``` % rg strings.Contains utils_test.go 84: if strings.Contains(s.State(), "run") { internal/stack/stacks_test.go 249: if strings.Contains(s.State(), "run") { ``` Resolves #41 Depends on #111
1 parent 91de685 commit ecabcf9

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8-
- No changes yet.
8+
### Fixed
9+
- Built-in ignores now match function names more accurately.
10+
They will no longer ignore stacks because of file names
11+
that look similar to function names.
912

1013
## [1.2.1]
1114
### Changed

options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017 Uber Technologies, Inc.
1+
// Copyright (c) 2017-2023 Uber Technologies, Inc.
22
//
33
// Permission is hereby granted, free of charge, to any person obtaining a copy
44
// of this software and associated documentation files (the "Software"), to deal
@@ -197,7 +197,7 @@ func isTestStack(s stack.Stack) bool {
197197
func isSyscallStack(s stack.Stack) bool {
198198
// Typically runs in the background when code uses CGo:
199199
// https://github.com/golang/go/issues/16714
200-
return s.FirstFunction() == "runtime.goexit" && strings.HasPrefix(s.State(), "syscall")
200+
return s.HasFunction("runtime.goexit") && strings.HasPrefix(s.State(), "syscall")
201201
}
202202

203203
func isStdLibStack(s stack.Stack) bool {
@@ -208,5 +208,5 @@ func isStdLibStack(s stack.Stack) bool {
208208
}
209209

210210
// Using signal.Notify will start a runtime goroutine.
211-
return strings.Contains(s.Full(), "runtime.ensureSigM")
211+
return s.HasFunction("runtime.ensureSigM")
212212
}

tracestack_new.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 Uber Technologies, Inc.
1+
// Copyright (c) 2021-2023 Uber Technologies, Inc.
22
//
33
// Permission is hereby granted, free of charge, to any person obtaining a copy
44
// of this software and associated documentation files (the "Software"), to deal
@@ -23,12 +23,8 @@
2323

2424
package goleak
2525

26-
import (
27-
"strings"
28-
29-
"go.uber.org/goleak/internal/stack"
30-
)
26+
import "go.uber.org/goleak/internal/stack"
3127

3228
func isTraceStack(s stack.Stack) bool {
33-
return strings.Contains(s.Full(), "runtime.ReadTrace")
29+
return s.HasFunction("runtime.ReadTrace")
3430
}

0 commit comments

Comments
 (0)