aboutsummaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-03-21 10:32:34 +0000
committerGitHub <noreply@github.com>2022-03-21 10:32:34 +0000
commit9572f5ed19abc0b635092108aa6956eaebc60578 (patch)
treeb4ed09d4db6406d0fe02a3d904125027d05aa333 /setup
parent8336ce972ec75b07b62f7b382c0e1e405d549545 (diff)
Wait for safe shutdown of NATS Server (#2289)
Diffstat (limited to 'setup')
-rw-r--r--setup/jetstream/nats.go14
-rw-r--r--setup/monolith.go2
2 files changed, 13 insertions, 3 deletions
diff --git a/setup/jetstream/nats.go b/setup/jetstream/nats.go
index 37597d58..43cc0331 100644
--- a/setup/jetstream/nats.go
+++ b/setup/jetstream/nats.go
@@ -6,6 +6,7 @@ import (
"time"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/process"
"github.com/sirupsen/logrus"
natsserver "github.com/nats-io/nats-server/v2/server"
@@ -15,7 +16,7 @@ import (
var natsServer *natsserver.Server
var natsServerMutex sync.Mutex
-func Prepare(cfg *config.JetStream) (natsclient.JetStreamContext, *natsclient.Conn) {
+func Prepare(process *process.ProcessContext, cfg *config.JetStream) (natsclient.JetStreamContext, *natsclient.Conn) {
// check if we need an in-process NATS Server
if len(cfg.Addresses) != 0 {
return setupNATS(cfg, nil)
@@ -35,7 +36,16 @@ func Prepare(cfg *config.JetStream) (natsclient.JetStreamContext, *natsclient.Co
panic(err)
}
natsServer.ConfigureLogger()
- go natsServer.Start()
+ go func() {
+ process.ComponentStarted()
+ natsServer.Start()
+ }()
+ go func() {
+ <-process.WaitForShutdown()
+ natsServer.Shutdown()
+ natsServer.WaitForShutdown()
+ process.ComponentFinished()
+ }()
}
natsServerMutex.Unlock()
if !natsServer.ReadyForConnections(time.Second * 10) {
diff --git a/setup/monolith.go b/setup/monolith.go
index 7dbd2eea..fa6d962c 100644
--- a/setup/monolith.go
+++ b/setup/monolith.go
@@ -57,7 +57,7 @@ type Monolith struct {
// AddAllPublicRoutes attaches all public paths to the given router
func (m *Monolith) AddAllPublicRoutes(process *process.ProcessContext, csMux, ssMux, keyMux, wkMux, mediaMux, synapseMux *mux.Router) {
clientapi.AddPublicRoutes(
- csMux, synapseMux, &m.Config.ClientAPI, m.AccountDB,
+ process, csMux, synapseMux, &m.Config.ClientAPI, m.AccountDB,
m.FedClient, m.RoomserverAPI,
m.EDUInternalAPI, m.AppserviceAPI, transactions.New(),
m.FederationAPI, m.UserAPI, m.KeyAPI,