Skip to content

Commit

Permalink
ignores: Don't use strings.Contains (#112)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abhinav authored Oct 23, 2023
1 parent 91de685 commit ecabcf9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

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

## [1.2.1]
### Changed
Expand Down
6 changes: 3 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2017-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -197,7 +197,7 @@ func isTestStack(s stack.Stack) bool {
func isSyscallStack(s stack.Stack) bool {
// Typically runs in the background when code uses CGo:
// https://github.com/golang/go/issues/16714
return s.FirstFunction() == "runtime.goexit" && strings.HasPrefix(s.State(), "syscall")
return s.HasFunction("runtime.goexit") && strings.HasPrefix(s.State(), "syscall")
}

func isStdLibStack(s stack.Stack) bool {
Expand All @@ -208,5 +208,5 @@ func isStdLibStack(s stack.Stack) bool {
}

// Using signal.Notify will start a runtime goroutine.
return strings.Contains(s.Full(), "runtime.ensureSigM")
return s.HasFunction("runtime.ensureSigM")
}
10 changes: 3 additions & 7 deletions tracestack_new.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Uber Technologies, Inc.
// Copyright (c) 2021-2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,12 +23,8 @@

package goleak

import (
"strings"

"go.uber.org/goleak/internal/stack"
)
import "go.uber.org/goleak/internal/stack"

func isTraceStack(s stack.Stack) bool {
return strings.Contains(s.Full(), "runtime.ReadTrace")
return s.HasFunction("runtime.ReadTrace")
}

0 comments on commit ecabcf9

Please sign in to comment.