Merge pull request #10363 from 2403905/issue-10360

Fix panic when stopping the nats
This commit is contained in:
Roman Perekhod
2024-10-22 12:34:34 +02:00
committed by GitHub
5 changed files with 14 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
Bugfix: Fix panic when stopping the nats
The nats server itself runs signal handling that the Shutdown() call in the ocis code is redundant and led to a panic.
https://github.com/owncloud/ocis/pull/10363
https://github.com/owncloud/ocis/issues/10360

View File

@@ -76,7 +76,7 @@ func Server(cfg *config.Config) *cli.Command {
}
gr.Add(func() error {
err := make(chan error)
err := make(chan error, 1)
select {
case <-ctx.Done():
return nil

View File

@@ -90,7 +90,7 @@ func Server(cfg *config.Config) *cli.Command {
}
gr.Add(func() error {
err := make(chan error)
err := make(chan error, 1)
select {
case <-ctx.Done():
return nil

View File

@@ -14,6 +14,7 @@ type NATSServer struct {
server *nserver.Server
}
// NatsOption configures the new NATSServer instance
func NewNATSServer(ctx context.Context, logger nserver.Logger, opts ...NatsOption) (*NATSServer, error) {
natsOpts := &nserver.Options{}
@@ -23,6 +24,8 @@ func NewNATSServer(ctx context.Context, logger nserver.Logger, opts ...NatsOptio
// enable JetStream
natsOpts.JetStream = true
// The NATS server itself runs the signal handling. We set `natsOpts.NoSigs = true` because we want to handle signals ourselves
natsOpts.NoSigs = true
server, err := nserver.NewServer(natsOpts)
if err != nil {
@@ -44,6 +47,8 @@ func (n *NATSServer) ListenAndServe() (err error) {
return nil
}
// Shutdown stops the NATSServer gracefully
func (n *NATSServer) Shutdown() {
n.server.Shutdown()
n.server.WaitForShutdown()
}

View File

@@ -66,7 +66,7 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
gr.Add(func() error {
err := make(chan error)
err := make(chan error, 1)
select {
case <-ctx.Done():
return nil