summaryrefslogtreecommitdiffhomepage
path: root/pkg/urpc
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-06-25 15:43:17 -0700
committergVisor bot <gvisor-bot@google.com>2021-06-25 15:43:17 -0700
commite5526f4f2696a2334d61b05f31ad23b7bee4342b (patch)
tree537f2f2c048137c2483b94c127059cbaf54dd642 /pkg/urpc
parentf00077e8d8d59ee6db93a3ece24c5f3f5156eda5 (diff)
parentd703340bc04a4269f420fdf24d946abcbc6a620b (diff)
Merge pull request #6222 from avagin:stop
PiperOrigin-RevId: 381561785
Diffstat (limited to 'pkg/urpc')
-rw-r--r--pkg/urpc/urpc.go51
1 files changed, 34 insertions, 17 deletions
diff --git a/pkg/urpc/urpc.go b/pkg/urpc/urpc.go
index 0e9a829f6..0ef635a2f 100644
--- a/pkg/urpc/urpc.go
+++ b/pkg/urpc/urpc.go
@@ -27,6 +27,7 @@ import (
"os"
"reflect"
"runtime"
+ "time"
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/log"
@@ -458,29 +459,45 @@ 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() {
- // Wait for all outstanding requests.
- defer s.wg.Wait()
-
+//
+// 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()
}
- // Close all known clients.
- s.mu.Lock()
- defer s.mu.Unlock()
- for client, state := range s.clients {
- switch state {
- case idle:
- // Close connection now.
- client.Close()
- s.clients[client] = closed
- case processing:
- // Request close when done.
- s.clients[client] = closeRequested
+ done := make(chan bool, 1)
+ go func() {
+ if timeout != 0 {
+ timer := time.NewTicker(timeout)
+ defer timer.Stop()
+ select {
+ case <-done:
+ return
+ case <-timer.C:
+ }
}
- }
+
+ // Close all known clients.
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ for client, state := range s.clients {
+ switch state {
+ case idle:
+ // Close connection now.
+ client.Close()
+ s.clients[client] = closed
+ case processing:
+ // Request close when done.
+ s.clients[client] = closeRequested
+ }
+ }
+ }()
+
+ // Wait for all outstanding requests.
+ s.wg.Wait()
+ done <- true
}
// Client is a urpc client.