diff options
Diffstat (limited to 'pkg/urpc/urpc.go')
-rw-r--r-- | pkg/urpc/urpc.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/pkg/urpc/urpc.go b/pkg/urpc/urpc.go index 7872d6fa1..0ef635a2f 100644 --- a/pkg/urpc/urpc.go +++ b/pkg/urpc/urpc.go @@ -20,7 +20,6 @@ package urpc import ( "bytes" - "context" "encoding/json" "errors" "fmt" @@ -28,6 +27,7 @@ import ( "os" "reflect" "runtime" + "time" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/log" @@ -459,18 +459,24 @@ func (s *Server) StartHandling(client *unet.Socket) { // No new requests should be initiated after calling Stop. Existing clients // will be closed after completing any pending RPCs. This method will block // until all clients have disconnected. -func (s *Server) Stop(ctx context.Context) { - done := make(chan bool) - +// +// timeout is the time for clients to complete ongoing RPCs. +func (s *Server) Stop(timeout time.Duration) { // Call any Stop callbacks. for _, stopper := range s.stoppers { stopper.Stop() } + + done := make(chan bool, 1) go func() { - select { - case <-done: - return - case <-ctx.Done(): + if timeout != 0 { + timer := time.NewTicker(timeout) + defer timer.Stop() + select { + case <-done: + return + case <-timer.C: + } } // Close all known clients. @@ -488,10 +494,10 @@ func (s *Server) Stop(ctx context.Context) { } } }() + // Wait for all outstanding requests. s.wg.Wait() done <- true - } // Client is a urpc client. |