Skip to content

Commit 984ef90

Browse files
laurazardvvoland
authored andcommitted
plugins: don't panic on Close if PluginServer nil
Signed-off-by: Laura Brehm <[email protected]> (cherry picked from commit 9c44806) Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 30c7951 commit 984ef90

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cli-plugins/socket/socket.go

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func (pl *PluginServer) Addr() net.Addr {
9595
//
9696
// The error value is that of the underlying [net.Listner.Close] call.
9797
func (pl *PluginServer) Close() error {
98+
if pl == nil {
99+
return nil
100+
}
98101
logrus.Trace("Closing plugin server")
99102
// Close connections first to ensure the connections get io.EOF instead
100103
// of a connection reset.

cli-plugins/socket/socket_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ func TestPluginServer(t *testing.T) {
117117
assert.NilError(t, err, "failed to dial returned server")
118118
checkDirNoNewPluginServer(t)
119119
})
120+
121+
t.Run("does not panic on Close if server is nil", func(t *testing.T) {
122+
var srv *PluginServer
123+
defer func() {
124+
if r := recover(); r != nil {
125+
t.Errorf("panicked on Close")
126+
}
127+
}()
128+
129+
err := srv.Close()
130+
assert.NilError(t, err)
131+
})
120132
}
121133

122134
func checkDirNoNewPluginServer(t *testing.T) {

0 commit comments

Comments
 (0)