Fix daemon socket ready race condition (bd-151)
Add WaitReady() channel to RPC server that signals when the socket is listening and ready to accept connections. Previously daemon startup waited a fixed 2 seconds which could fail if the server took longer. Changes: - Add readyChan to Server struct - Signal ready after listener bind completes - Update daemon startup to wait on WaitReady() channel - Increase timeout to 5s with proper signaling This fixes multi-repo daemon routing test failures where daemon would start but not be ready to handle requests within the timeout window. Amp-Thread-ID: https://ampcode.com/threads/T-675a2db5-b1b3-480d-a108-b003d8139d08 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -60,6 +60,8 @@ type Server struct {
|
||||
connSemaphore chan struct{}
|
||||
// Request timeout
|
||||
requestTimeout time.Duration
|
||||
// Ready channel signals when server is listening
|
||||
readyChan chan struct{}
|
||||
}
|
||||
|
||||
// NewServer creates a new RPC server
|
||||
@@ -108,6 +110,7 @@ func NewServer(socketPath string, store storage.Storage) *Server {
|
||||
maxConns: maxConns,
|
||||
connSemaphore: make(chan struct{}, maxConns),
|
||||
requestTimeout: requestTimeout,
|
||||
readyChan: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +140,9 @@ func (s *Server) Start(ctx context.Context) error {
|
||||
s.listener = listener
|
||||
s.mu.Unlock()
|
||||
|
||||
// Signal that server is ready to accept connections
|
||||
close(s.readyChan)
|
||||
|
||||
go s.handleSignals()
|
||||
go s.runCleanupLoop()
|
||||
|
||||
@@ -177,6 +183,11 @@ func (s *Server) Start(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// WaitReady waits for the server to be ready to accept connections
|
||||
func (s *Server) WaitReady() <-chan struct{} {
|
||||
return s.readyChan
|
||||
}
|
||||
|
||||
// Stop stops the RPC server and cleans up resources
|
||||
func (s *Server) Stop() error {
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user