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
+6
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
+1 -1
View File
@@ -76,7 +76,7 @@ func Server(cfg *config.Config) *cli.Command {
} }
gr.Add(func() error { gr.Add(func() error {
err := make(chan error) err := make(chan error, 1)
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil return nil
+1 -1
View File
@@ -90,7 +90,7 @@ func Server(cfg *config.Config) *cli.Command {
} }
gr.Add(func() error { gr.Add(func() error {
err := make(chan error) err := make(chan error, 1)
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil return nil
+5
View File
@@ -14,6 +14,7 @@ type NATSServer struct {
server *nserver.Server server *nserver.Server
} }
// NatsOption configures the new NATSServer instance
func NewNATSServer(ctx context.Context, logger nserver.Logger, opts ...NatsOption) (*NATSServer, error) { func NewNATSServer(ctx context.Context, logger nserver.Logger, opts ...NatsOption) (*NATSServer, error) {
natsOpts := &nserver.Options{} natsOpts := &nserver.Options{}
@@ -23,6 +24,8 @@ func NewNATSServer(ctx context.Context, logger nserver.Logger, opts ...NatsOptio
// enable JetStream // enable JetStream
natsOpts.JetStream = true 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) server, err := nserver.NewServer(natsOpts)
if err != nil { if err != nil {
@@ -44,6 +47,8 @@ func (n *NATSServer) ListenAndServe() (err error) {
return nil return nil
} }
// Shutdown stops the NATSServer gracefully
func (n *NATSServer) Shutdown() { func (n *NATSServer) Shutdown() {
n.server.Shutdown() n.server.Shutdown()
n.server.WaitForShutdown()
} }
@@ -66,7 +66,7 @@ func Server(cfg *config.Config) *cli.Command {
return err return err
} }
gr.Add(func() error { gr.Add(func() error {
err := make(chan error) err := make(chan error, 1)
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil return nil