This is an automated email from the ASF dual-hosted git repository.

git-hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 07079ab55 fix(tests): prevent port collisions during parallel server 
startup (#3677)
07079ab55 is described below

commit 07079ab55ee836546f71e969af3ea485d0ef86e6
Author: hulk <[email protected]>
AuthorDate: Thu Oct 15 18:53:55 2026 -0700

    fix(tests): prevent port collisions during parallel server startup (#3677)
    
    Parallel Go integration tests can select the same server port and send
    commands to another test’s Kvrocks instance.
    
    `findFreePort` releases its listener before Kvrocks binds the selected
    port. Another concurrent startup can select that port during this gap.
    Because Kvrocks enables `SO_REUSEPORT`, both servers can bind
    successfully,
    allowing clients to reach the wrong server and observe unexpected state.
    
    Serialize port selection and startup across test processes sharing a
    workspace. Hold the lock until the server is ready so subsequent
    startups
    select a different port. Tests continue running in parallel after
    startup.
    
    See:
    
    -
    
[https://github.com/apache/kvrocks/actions/runs/38501022267/job/115657680018](https://github.com/apache/kvrocks/actions/runs/38501022267/job/115657680018)
    -
    
[https://github.com/apache/kvrocks/actions/runs/38033115108/job/114158108984](https://github.com/apache/kvrocks/actions/runs/38033115108/job/114158108984)
    
    Assistant-By GPT-6
---
 tests/gocase/util/server.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go
index ea8ee4742..194dd3631 100644
--- a/tests/gocase/util/server.go
+++ b/tests/gocase/util/server.go
@@ -225,6 +225,15 @@ func StartServerWithCLIOptions(
        require.NotEmpty(t, b, "please set the binary path by `-binPath`")
        cmd := exec.Command(b)
 
+       // findFreePort releases the port before Kvrocks binds it, so parallel 
tests can
+       // select the same port. SO_REUSEPORT lets both servers bind it, and 
clients may
+       // reach the wrong server. Serialize port selection and startup across 
test
+       // processes until the server is ready.
+       lock, err := os.OpenFile(filepath.Join(*workspace, 
"server-start.lock"), os.O_CREATE|os.O_RDWR, 0o600)
+       require.NoError(t, err)
+       defer func() { require.NoError(t, lock.Close()) }()
+       require.NoError(t, syscall.Flock(int(lock.Fd()), syscall.LOCK_EX))
+
        addr, err := findFreePort()
        require.NoError(t, err)
        if configs["bind"] == "" {

Reply via email to