Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Griffiths <[email protected]>
  • Loading branch information
Grant Griffiths committed Sep 12, 2023
1 parent 0447163 commit 40512cf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions csi/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package csi
import (
"fmt"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -98,6 +97,7 @@ type OsdCsiServer struct {
allowInlineVolumes bool
stopCleanupCh chan bool
config *OsdCsiServerConfig
autoRecoverStopCh chan struct{}
}

// NewOsdCsiServer creates a gRPC CSI complient server on the
Expand Down Expand Up @@ -244,8 +244,10 @@ func (s *OsdCsiServer) Start() error {
}

if s.config.Net == "unix" {
stopCh := make(chan struct{})
s.autoRecoverStopCh = stopCh
go func() {
err := autoSocketRecover(s)
err := autoSocketRecover(s, stopCh)
if err != nil {
logrus.Errorf("failed to start CSI driver socket auto-recover watcher: %v", err)
}
Expand All @@ -257,6 +259,7 @@ func (s *OsdCsiServer) Start() error {

// Start is used to stop the server.
func (s *OsdCsiServer) Stop() {
close(s.autoRecoverStopCh)
s.GrpcServer.Stop()
}

Expand Down Expand Up @@ -297,12 +300,17 @@ func createGrpcServer(config *OsdCsiServerConfig) (*grpcserver.GrpcServer, error
return gServer, nil
}

func autoSocketRecover(s *OsdCsiServer) error {
socketPath := strings.TrimPrefix(s.Address(), "unix://")
func autoSocketRecover(s *OsdCsiServer, stopCh chan struct{}) error {
socketPath := s.Address()
ticker := time.NewTicker(csiSocketCheckInterval)

// Start checking for CSI socket delete
for {
time.Sleep(csiSocketCheckInterval)
select {
case <-stopCh:
return nil
case <-ticker.C:
}

// Check if socket deleted
_, err := os.Stat(socketPath)
Expand Down

0 comments on commit 40512cf

Please sign in to comment.