milvus/internal
liliu-z 95ee65e950
fix: Fix race condition in Zilliz client tests (#45832)
issue: #45831

This PR fixes a race condition in `TestZillizClient` test cases where
`t.Logf`
could be called after the test function had returned, leading to a panic
or data race failure.

Root cause:
1. Incorrect defer order: `defer s.Stop()` was called after `defer
lis.Close()`.
This caused `lis.Accept()` to return an error before `s.Stop()` had set
the quit flag,
   triggering the error handling path in the server goroutine.
2. Unsafe logging: The error handling path used `t.Logf` inside a
goroutine, which
   is unsafe if the main test function exits before the log is printed.

Fixes:
- Changed defer order to ensure `s.Stop()` is called before
`lis.Close()`.
- Replaced `t.Logf` with `fmt.Printf` in the background goroutine to
avoid panic on test completion.

Signed-off-by: Li Liu <li.liu@zilliz.com>
2025-11-26 21:13:09 +08:00
..