Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Write goroutine dumps to file good/bad
  • Loading branch information
mafredri committed May 25, 2023
commit 2ce53910fce25ebb2460d1c696eb4351831ab8dc
18 changes: 17 additions & 1 deletion tailnet/conn_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tailnet_test

import (
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -363,6 +364,7 @@ func runTestTransmitHang(t *testing.T, timeout time.Duration) {
size := 0
retries := 0
writeTimeout := 2 * time.Second
goroutineGoodDumpWritten := false
for i := 0; i < 1024*2; i++ {
logger.Debug(ctx, "write payload", slog.F("num", i), slog.F("transmitted_kb", size/1024))
Retry:
Expand All @@ -373,14 +375,28 @@ func runTestTransmitHang(t *testing.T, timeout time.Duration) {
})
if err != nil {
if time.Duration(retries)*writeTimeout < timeout {
_ = pprof.Lookup("goroutine").WriteTo(testLog, 1)
var b bytes.Buffer
_ = pprof.Lookup("goroutine").WriteTo(&b, 1)
logger.Error(ctx, "write failed", slog.Error(err))
_, _ = testLog.Write(b.Bytes())
f, err := os.Create(filepath.Join(captureDir, fmt.Sprintf("goroutine-bad-%d.txt", i)))
if err == nil {
_, _ = f.Write(b.Bytes())
_ = f.Close()
}
retries++
logger.Info(ctx, "retrying", slog.F("try", retries))
goto Retry
} else {
require.NoError(t, err)
}
} else if !goroutineGoodDumpWritten {
f, err := os.Create(filepath.Join(captureDir, fmt.Sprintf("goroutine-good-%d.txt", i)))
if err == nil {
_ = pprof.Lookup("goroutine").WriteTo(f, 1)
_ = f.Close()
goroutineGoodDumpWritten = true
}
}
size += n
}
Expand Down