Skip to content

Commit

Permalink
Merge pull request #1 from waynepeking348/add_comment_for_server_skel…
Browse files Browse the repository at this point in the history
…eton

add comments for grpc skeleton
csfldf authored Apr 19, 2023
2 parents 685e0e6 + ba41b8b commit f31ac4e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/plugins/skeleton/generic.go
Original file line number Diff line number Diff line change
@@ -224,6 +224,7 @@ func (p *PluginRegistrationWrapper) start() (startError error) {
p.Unlock()
if startError != nil {
klog.Errorf("start %s failed with error: %v", p.Name(), startError)
// call stop to revert executed start steps for all servers
_ = p.stop()
}
}()
@@ -323,6 +324,10 @@ func (p *PluginRegistrationWrapper) serve() error {
p.serverRegister(server)
watcherapi.RegisterRegistrationServer(server, p)

// server.Serve works in a separate goroutine; we will retry several times if
// it crashes, and trigger restart if it exceeds retry thresholds.
// if the server stops, server.Serve will return will nil error, so the for loop
// can be break successfully without causing goroutine leaks.
go func() {
lastCrashTime := time.Now()
restartCount := 0
@@ -351,6 +356,7 @@ func (p *PluginRegistrationWrapper) serve() error {
}
}()

// try to connect with the server to ensure the serving works as expected
err = func() error {
ctx, cancel := context.WithTimeout(context.Background(), grpcTimeout)
defer cancel()
@@ -362,7 +368,6 @@ func (p *PluginRegistrationWrapper) serve() error {
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
}),
)

if err != nil {
return err
}
@@ -371,7 +376,6 @@ func (p *PluginRegistrationWrapper) serve() error {

return nil
}()

if err != nil {
server.Stop()
return fmt.Errorf("dial check for %s at socket: %s failed with err: %v", p.Name(), curSocket, err)

0 comments on commit f31ac4e

Please sign in to comment.