Skip to content

Commit

Permalink
fix(timeout.go): remove redundant leaked go func in RegisterTimeoutHa…
Browse files Browse the repository at this point in the history
…ndler (#4004)

<!-- Thanks for sending a PR! Before submitting:

1. If this is your first PR, please read CONTRIBUTING.md and sign the
CLA
   first. We cannot review code without a signed CLA.
2. Please file an issue *first*. All features and most bug fixes should
have
an associated issue with a design discussed and decided upon. Small bug
   fixes and documentation improvements don't need issues.
3. New features and bug fixes must have tests. Documentation may need to
be updated. If you're unsure what to update, send the PR, and we'll
discuss
   in review.
4. Note that PRs updating dependencies and new Go versions are not
accepted.
   Please file an issue instead.
-->

**What type of PR is this?**

Bug fix

**What does this PR do? Why is it needed?**

Fix #4003 

The removed goroutine is redundant and will fail user code tests where
timeout or sigterm do no happen.

IIUC, we only need to register a noop handler for sigterm signal for
bazel to gracefully shutdown in case of a test timeout and
`signal.Notify(c, signal.SIGTERM)` create a strong reference to prevent
`c` from being GCed when `RegisterTimeoutHandler` returns.

**Which issues(s) does this PR fix?**

Fixes #4003

**Other notes for review**

Tested with my own repo tests and a simple time.Sleep ran with
--test_timeout
  • Loading branch information
Roytangrb authored Aug 2, 2024
1 parent c326d40 commit 5ec14ee
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions go/tools/bzltestutil/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@ func RegisterTimeoutHandler() {
// (2): https://github.com/bazelbuild/rules_go/pull/3929
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
}()
}

0 comments on commit 5ec14ee

Please sign in to comment.