plugins: don't panic on Close if PluginServer nil
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
Родитель
87c6624cb7
Коммит
9c4480604e
|
@ -95,6 +95,9 @@ func (pl *PluginServer) Addr() net.Addr {
|
||||||
//
|
//
|
||||||
// The error value is that of the underlying [net.Listner.Close] call.
|
// The error value is that of the underlying [net.Listner.Close] call.
|
||||||
func (pl *PluginServer) Close() error {
|
func (pl *PluginServer) Close() error {
|
||||||
|
if pl == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
logrus.Trace("Closing plugin server")
|
logrus.Trace("Closing plugin server")
|
||||||
// Close connections first to ensure the connections get io.EOF instead
|
// Close connections first to ensure the connections get io.EOF instead
|
||||||
// of a connection reset.
|
// of a connection reset.
|
||||||
|
|
|
@ -117,6 +117,18 @@ func TestPluginServer(t *testing.T) {
|
||||||
assert.NilError(t, err, "failed to dial returned server")
|
assert.NilError(t, err, "failed to dial returned server")
|
||||||
checkDirNoNewPluginServer(t)
|
checkDirNoNewPluginServer(t)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("does not panic on Close if server is nil", func(t *testing.T) {
|
||||||
|
var srv *PluginServer
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
t.Errorf("panicked on Close")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := srv.Close()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkDirNoNewPluginServer(t *testing.T) {
|
func checkDirNoNewPluginServer(t *testing.T) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче