mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
test(scaletest/workspacetraffic): fix test flake due to io.EOF on close (#21231)
Fixes coder/internal#119
This commit is contained in:
committed by
GitHub
parent
96fca0188e
commit
498c565fc7
@@ -147,8 +147,9 @@ func connectSSH(ctx context.Context, client *codersdk.Client, agentID uuid.UUID,
|
|||||||
var closers []func() error
|
var closers []func() error
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, c := range closers {
|
// Reverse order, like defer.
|
||||||
if err2 := c(); err2 != nil {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
|
if err2 := closers[i](); err2 != nil {
|
||||||
err = errors.Join(err, err2)
|
err = errors.Join(err, err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,8 +228,9 @@ func connectSSH(ctx context.Context, client *codersdk.Client, agentID uuid.UUID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, c := range closers {
|
// Reverse order, like defer.
|
||||||
if err := c(); err != nil {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
|
if err := closers[i](); err != nil {
|
||||||
if !errors.Is(err, io.EOF) {
|
if !errors.Is(err, io.EOF) {
|
||||||
merr = errors.Join(merr, err)
|
merr = errors.Join(merr, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package workspacetraffic
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -131,8 +132,11 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) (err error)
|
|||||||
closeConn := func() error {
|
closeConn := func() error {
|
||||||
closeOnce.Do(func() {
|
closeOnce.Do(func() {
|
||||||
closeErr = conn.Close()
|
closeErr = conn.Close()
|
||||||
if closeErr != nil {
|
if errors.Is(closeErr, io.EOF) {
|
||||||
|
closeErr = nil
|
||||||
|
} else if closeErr != nil {
|
||||||
logger.Error(ctx, "close agent connection", slog.Error(closeErr))
|
logger.Error(ctx, "close agent connection", slog.Error(closeErr))
|
||||||
|
closeErr = xerrors.Errorf("close agent connection: %w", closeErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return closeErr
|
return closeErr
|
||||||
|
|||||||
Reference in New Issue
Block a user