Skip to content

Commit

Permalink
proxy: fix flaky TestAuditLogging (#2575)
Browse files Browse the repository at this point in the history
The TestAuditLogging could flake because it checks audit log after
receiving response message from the connection which may happen
before write to audit log by io.MultiWriter has finished.

It could be reproduced via:
```
go test ./proxy -run=TestAuditLogging -count=10000 -failfast
```

This change writes to auditLog before writing to the connection which
also would show failed message in the audit log in case write to
connection fails.

Fixes #2572

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Sep 4, 2023
1 parent 88abbf3 commit ff9a521
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion proxy/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p *upgradeProxy) serveHTTP(w http.ResponseWriter, req *http.Request) {
done := make(chan struct{}, 2)

if p.useAuditLog {
copyAsync("backend->request+audit", backendConn, io.MultiWriter(requestHijackedConn, p.auditLogOut), done)
copyAsync("backend->request+audit", backendConn, io.MultiWriter(p.auditLogOut, requestHijackedConn), done)
} else {
copyAsync("backend->request", backendConn, requestHijackedConn, done)
}
Expand Down
3 changes: 1 addition & 2 deletions proxy/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,9 @@ func TestAuditLogging(t *testing.T) {
return func(t *testing.T) {
wss := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) {
if _, err := io.Copy(ws, ws); err != nil {
t.Fatal(err)
t.Error(err)
}
}))

defer wss.Close()

// only used as poor man's sync, the audit log in question goes stdout and stderr,
Expand Down

0 comments on commit ff9a521

Please sign in to comment.