Skip to content

Commit 600bfc3

Browse files
committed
Merge branch 'sh-fix-test-stack-dumping-flakiness' into 'main'
Fix TestStackDumping test freezing See merge request https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/5210 Merged-by: Stan Hu <[email protected]> Approved-by: Axel von Bertoldi <[email protected]>
2 parents 85d37a7 + 5bdf579 commit 600bfc3

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

log/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (l *Config) enableGoroutinesDump() {
138138

139139
l.goroutinesDumpStopCh = make(chan bool)
140140

141-
watchForGoroutinesDump(l.logger, l.goroutinesDumpStopCh)
141+
watchForGoroutinesDump(l.logger, l.goroutinesDumpStopCh, false)
142142
}
143143

144144
func (l *Config) disableGoroutinesDump() {

log/dump_unix.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/sirupsen/logrus"
1212
)
1313

14-
func watchForGoroutinesDump(logger *logrus.Logger, stopCh chan bool) (chan bool, chan bool) {
14+
func watchForGoroutinesDump(logger *logrus.Logger, stopCh chan bool, blocking bool) (chan bool, chan bool) {
1515
dumpedCh := make(chan bool)
1616
finishedCh := make(chan bool)
1717

@@ -27,7 +27,7 @@ func watchForGoroutinesDump(logger *logrus.Logger, stopCh chan bool) (chan bool,
2727
len := runtime.Stack(buf, true)
2828
logger.Printf("=== received SIGUSR1 ===\n*** goroutine dump...\n%s\n*** end\n", buf[0:len])
2929

30-
nonBlockingSend(dumpedCh, true)
30+
signalChannel(dumpedCh, true, blocking)
3131
case <-stopCh:
3232
close(finishedCh)
3333
return
@@ -38,6 +38,14 @@ func watchForGoroutinesDump(logger *logrus.Logger, stopCh chan bool) (chan bool,
3838
return dumpedCh, finishedCh
3939
}
4040

41+
func signalChannel(ch chan bool, value bool, blocking bool) {
42+
if blocking {
43+
ch <- value
44+
} else {
45+
nonBlockingSend(ch, value)
46+
}
47+
}
48+
4149
func nonBlockingSend(ch chan bool, value bool) {
4250
select {
4351
case ch <- value:

log/dump_unix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestStackDumping(t *testing.T) {
1919

2020
stopCh := make(chan bool)
2121

22-
dumpedCh, finishedCh := watchForGoroutinesDump(logger, stopCh)
22+
dumpedCh, finishedCh := watchForGoroutinesDump(logger, stopCh, true)
2323
require.NotNil(t, dumpedCh)
2424
require.NotNil(t, finishedCh)
2525

log/dump_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import (
44
"github.com/sirupsen/logrus"
55
)
66

7-
func watchForGoroutinesDump(logger *logrus.Logger, stopCh chan bool) (chan bool, chan bool) {
7+
func watchForGoroutinesDump(logger *logrus.Logger, stopCh chan bool, blocking bool) (chan bool, chan bool) {
88
return nil, nil
99
}

0 commit comments

Comments
 (0)