2020-06-12 15:55:57 +02:00
|
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
2018-01-02 11:26:56 +01:00
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
2021-11-24 11:45:23 +01:00
|
|
|
|
package base
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
|
|
|
|
import (
|
2021-01-26 13:56:20 +01:00
|
|
|
|
"context"
|
2020-10-20 18:13:12 +02:00
|
|
|
|
"crypto/tls"
|
2022-05-03 17:35:06 +02:00
|
|
|
|
"database/sql"
|
2022-10-04 14:02:41 +02:00
|
|
|
|
"encoding/json"
|
2020-06-02 22:02:24 +02:00
|
|
|
|
"fmt"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
"io"
|
2020-10-20 18:13:12 +02:00
|
|
|
|
"net"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
"net/http"
|
2022-04-27 15:05:49 +02:00
|
|
|
|
_ "net/http/pprof"
|
2021-01-26 13:56:20 +01:00
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
2022-08-30 13:59:13 +02:00
|
|
|
|
"sync"
|
2021-01-26 13:56:20 +01:00
|
|
|
|
"syscall"
|
2020-04-03 12:40:50 +02:00
|
|
|
|
"time"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
2021-03-24 11:25:24 +01:00
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
|
|
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-08-13 13:16:37 +02:00
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2021-01-26 13:56:20 +01:00
|
|
|
|
"go.uber.org/atomic"
|
2020-10-20 18:13:12 +02:00
|
|
|
|
"golang.org/x/net/http2"
|
|
|
|
|
"golang.org/x/net/http2/h2c"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
2022-09-27 18:06:49 +02:00
|
|
|
|
"github.com/matrix-org/dendrite/internal"
|
2022-08-30 13:59:13 +02:00
|
|
|
|
"github.com/matrix-org/dendrite/internal/caching"
|
2022-09-07 18:15:54 +02:00
|
|
|
|
"github.com/matrix-org/dendrite/internal/fulltext"
|
2022-08-30 13:59:13 +02:00
|
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
|
|
|
|
"github.com/matrix-org/dendrite/internal/pushgateway"
|
|
|
|
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
|
|
|
|
|
2018-01-02 11:26:56 +01:00
|
|
|
|
"github.com/gorilla/mux"
|
2022-04-27 14:36:40 +02:00
|
|
|
|
"github.com/kardianos/minwinsvc"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
2022-08-30 13:59:13 +02:00
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
|
2018-07-17 16:36:04 +02:00
|
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2020-06-04 16:43:07 +02:00
|
|
|
|
asinthttp "github.com/matrix-org/dendrite/appservice/inthttp"
|
2021-11-24 11:45:23 +01:00
|
|
|
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
|
|
|
|
federationIntHTTP "github.com/matrix-org/dendrite/federationapi/inthttp"
|
2020-07-13 17:02:35 +02:00
|
|
|
|
keyserverAPI "github.com/matrix-org/dendrite/keyserver/api"
|
|
|
|
|
keyinthttp "github.com/matrix-org/dendrite/keyserver/inthttp"
|
2018-07-17 16:36:04 +02:00
|
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-06-04 16:43:07 +02:00
|
|
|
|
rsinthttp "github.com/matrix-org/dendrite/roomserver/inthttp"
|
2020-12-02 18:41:00 +01:00
|
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2022-09-27 18:06:49 +02:00
|
|
|
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
|
|
|
|
"github.com/matrix-org/dendrite/setup/process"
|
2020-06-16 15:10:55 +02:00
|
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
|
|
|
|
userapiinthttp "github.com/matrix-org/dendrite/userapi/inthttp"
|
2018-01-02 11:26:56 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// BaseDendrite is a base for creating new instances of dendrite. It parses
|
|
|
|
|
// command line flags and config, and exposes methods for creating various
|
|
|
|
|
// resources. All errors are handled by logging then exiting, so all methods
|
|
|
|
|
// should only be used during start up.
|
|
|
|
|
// Must be closed when shutting down.
|
|
|
|
|
type BaseDendrite struct {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
*process.ProcessContext
|
2020-08-13 13:16:37 +02:00
|
|
|
|
componentName string
|
|
|
|
|
tracerCloser io.Closer
|
|
|
|
|
PublicClientAPIMux *mux.Router
|
|
|
|
|
PublicFederationAPIMux *mux.Router
|
|
|
|
|
PublicKeyAPIMux *mux.Router
|
|
|
|
|
PublicMediaAPIMux *mux.Router
|
2021-09-10 11:05:31 +02:00
|
|
|
|
PublicWellKnownAPIMux *mux.Router
|
2020-08-13 13:16:37 +02:00
|
|
|
|
InternalAPIMux *mux.Router
|
2022-03-25 14:25:15 +01:00
|
|
|
|
DendriteAdminMux *mux.Router
|
2021-07-09 17:52:31 +02:00
|
|
|
|
SynapseAdminMux *mux.Router
|
2022-05-09 15:15:24 +02:00
|
|
|
|
NATS *jetstream.NATSInstance
|
2020-08-13 13:16:37 +02:00
|
|
|
|
UseHTTPAPIs bool
|
2020-10-01 12:55:17 +02:00
|
|
|
|
apiHttpClient *http.Client
|
2020-08-13 13:16:37 +02:00
|
|
|
|
Cfg *config.Dendrite
|
|
|
|
|
Caches *caching.Caches
|
2021-01-22 15:16:59 +01:00
|
|
|
|
DNSCache *gomatrixserverlib.DNSCache
|
2022-05-03 17:35:06 +02:00
|
|
|
|
Database *sql.DB
|
|
|
|
|
DatabaseWriter sqlutil.Writer
|
2022-05-09 18:23:02 +02:00
|
|
|
|
EnableMetrics bool
|
2022-09-07 18:15:54 +02:00
|
|
|
|
Fulltext *fulltext.Search
|
2022-08-30 13:59:13 +02:00
|
|
|
|
startupLock sync.Mutex
|
2018-01-02 11:26:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 11:45:23 +01:00
|
|
|
|
const NoListener = ""
|
|
|
|
|
|
2020-04-20 18:42:34 +02:00
|
|
|
|
const HTTPServerTimeout = time.Minute * 5
|
|
|
|
|
const HTTPClientTimeout = time.Second * 30
|
|
|
|
|
|
2021-11-24 11:45:23 +01:00
|
|
|
|
type BaseDendriteOptions int
|
|
|
|
|
|
|
|
|
|
const (
|
2022-05-09 18:23:02 +02:00
|
|
|
|
DisableMetrics BaseDendriteOptions = iota
|
2021-11-24 11:45:23 +01:00
|
|
|
|
UseHTTPAPIs
|
2022-05-06 14:51:48 +02:00
|
|
|
|
PolylithMode
|
2021-11-24 11:45:23 +01:00
|
|
|
|
)
|
2020-08-13 13:16:37 +02:00
|
|
|
|
|
2018-01-02 11:26:56 +01:00
|
|
|
|
// NewBaseDendrite creates a new instance to be used by a component.
|
|
|
|
|
// The componentName is used for logging purposes, and should be a friendly name
|
|
|
|
|
// of the compontent running, e.g. "SyncAPI"
|
2021-11-24 11:45:23 +01:00
|
|
|
|
func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...BaseDendriteOptions) *BaseDendrite {
|
2022-03-11 18:27:12 +01:00
|
|
|
|
platformSanityChecks()
|
2021-11-24 11:45:23 +01:00
|
|
|
|
useHTTPAPIs := false
|
2022-05-09 18:23:02 +02:00
|
|
|
|
enableMetrics := true
|
2022-05-06 14:51:48 +02:00
|
|
|
|
isMonolith := true
|
2021-11-24 11:45:23 +01:00
|
|
|
|
for _, opt := range options {
|
|
|
|
|
switch opt {
|
2022-05-09 18:23:02 +02:00
|
|
|
|
case DisableMetrics:
|
|
|
|
|
enableMetrics = false
|
2021-11-24 11:45:23 +01:00
|
|
|
|
case UseHTTPAPIs:
|
|
|
|
|
useHTTPAPIs = true
|
2022-05-06 14:51:48 +02:00
|
|
|
|
case PolylithMode:
|
|
|
|
|
isMonolith = false
|
|
|
|
|
useHTTPAPIs = true
|
2021-11-24 11:45:23 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 15:18:04 +02:00
|
|
|
|
configErrors := &config.ConfigErrors{}
|
2022-05-03 17:35:06 +02:00
|
|
|
|
cfg.Verify(configErrors, isMonolith)
|
2020-08-10 15:18:04 +02:00
|
|
|
|
if len(*configErrors) > 0 {
|
|
|
|
|
for _, err := range *configErrors {
|
|
|
|
|
logrus.Errorf("Configuration error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
logrus.Fatalf("Failed to start due to configuration errors")
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 15:40:13 +02:00
|
|
|
|
internal.SetupStdLogging()
|
|
|
|
|
internal.SetupHookLogging(cfg.Logging, componentName)
|
|
|
|
|
internal.SetupPprof()
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
2020-09-02 17:18:08 +02:00
|
|
|
|
logrus.Infof("Dendrite version %s", internal.VersionString())
|
|
|
|
|
|
2022-04-29 09:31:11 +02:00
|
|
|
|
if !cfg.ClientAPI.RegistrationDisabled && cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled {
|
|
|
|
|
logrus.Warn("Open registration is enabled")
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 11:26:56 +01:00
|
|
|
|
closer, err := cfg.SetupTracing("Dendrite" + componentName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logrus.WithError(err).Panicf("failed to start opentracing")
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 18:15:54 +02:00
|
|
|
|
var fts *fulltext.Search
|
|
|
|
|
isSyncOrMonolith := componentName == "syncapi" || isMonolith
|
|
|
|
|
if cfg.SyncAPI.Fulltext.Enabled && isSyncOrMonolith {
|
|
|
|
|
fts, err = fulltext.New(cfg.SyncAPI.Fulltext)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logrus.WithError(err).Panicf("failed to create full text")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 11:25:24 +01:00
|
|
|
|
if cfg.Global.Sentry.Enabled {
|
|
|
|
|
logrus.Info("Setting up Sentry for debugging...")
|
|
|
|
|
err = sentry.Init(sentry.ClientOptions{
|
|
|
|
|
Dsn: cfg.Global.Sentry.DSN,
|
|
|
|
|
Environment: cfg.Global.Sentry.Environment,
|
|
|
|
|
Debug: true,
|
|
|
|
|
ServerName: string(cfg.Global.ServerName),
|
|
|
|
|
Release: "dendrite@" + internal.VersionString(),
|
|
|
|
|
AttachStacktrace: true,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
logrus.WithError(err).Panic("failed to start Sentry")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 15:16:59 +01:00
|
|
|
|
var dnsCache *gomatrixserverlib.DNSCache
|
|
|
|
|
if cfg.Global.DNSCache.Enabled {
|
|
|
|
|
dnsCache = gomatrixserverlib.NewDNSCache(
|
|
|
|
|
cfg.Global.DNSCache.CacheSize,
|
2021-07-16 20:42:53 +02:00
|
|
|
|
cfg.Global.DNSCache.CacheLifetime,
|
2021-01-22 15:16:59 +01:00
|
|
|
|
)
|
|
|
|
|
logrus.Infof(
|
|
|
|
|
"DNS cache enabled (size %d, lifetime %s)",
|
|
|
|
|
cfg.Global.DNSCache.CacheSize,
|
2021-07-16 20:42:53 +02:00
|
|
|
|
cfg.Global.DNSCache.CacheLifetime,
|
2021-01-22 15:16:59 +01:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 18:13:12 +02:00
|
|
|
|
apiClient := http.Client{
|
|
|
|
|
Timeout: time.Minute * 10,
|
|
|
|
|
Transport: &http2.Transport{
|
|
|
|
|
AllowHTTP: true,
|
|
|
|
|
DialTLS: func(network, addr string, _ *tls.Config) (net.Conn, error) {
|
|
|
|
|
// Ordinarily HTTP/2 would expect TLS, but the remote listener is
|
|
|
|
|
// H2C-enabled (HTTP/2 without encryption). Overriding the DialTLS
|
|
|
|
|
// function with a plain Dial allows us to trick the HTTP client
|
|
|
|
|
// into establishing a HTTP/2 connection without TLS.
|
|
|
|
|
// TODO: Eventually we will want to look at authenticating and
|
|
|
|
|
// encrypting these internal HTTP APIs, at which point we will have
|
|
|
|
|
// to reconsider H2C and change all this anyway.
|
|
|
|
|
return net.Dial(network, addr)
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2020-06-02 22:02:24 +02:00
|
|
|
|
|
2022-05-03 17:35:06 +02:00
|
|
|
|
// If we're in monolith mode, we'll set up a global pool of database
|
|
|
|
|
// connections. A component is welcome to use this pool if they don't
|
|
|
|
|
// have a separate database config of their own.
|
|
|
|
|
var db *sql.DB
|
|
|
|
|
var writer sqlutil.Writer
|
|
|
|
|
if cfg.Global.DatabaseOptions.ConnectionString != "" {
|
|
|
|
|
if !isMonolith {
|
|
|
|
|
logrus.Panic("Using a global database connection pool is not supported in polylith deployments")
|
|
|
|
|
}
|
|
|
|
|
if cfg.Global.DatabaseOptions.ConnectionString.IsSQLite() {
|
|
|
|
|
logrus.Panic("Using a global database connection pool is not supported with SQLite databases")
|
|
|
|
|
}
|
2022-05-03 18:40:56 +02:00
|
|
|
|
writer = sqlutil.NewDummyWriter()
|
|
|
|
|
if db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, writer); err != nil {
|
2022-05-03 17:35:06 +02:00
|
|
|
|
logrus.WithError(err).Panic("Failed to set up global database connections")
|
|
|
|
|
}
|
|
|
|
|
logrus.Debug("Using global database connection pool")
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 12:14:08 +02:00
|
|
|
|
// Ideally we would only use SkipClean on routes which we know can allow '/' but due to
|
|
|
|
|
// https://github.com/gorilla/mux/issues/460 we have to attach this at the top router.
|
|
|
|
|
// When used in conjunction with UseEncodedPath() we get the behaviour we want when parsing
|
|
|
|
|
// path parameters:
|
|
|
|
|
// /foo/bar%2Fbaz == [foo, bar%2Fbaz] (from UseEncodedPath)
|
|
|
|
|
// /foo/bar%2F%2Fbaz == [foo, bar%2F%2Fbaz] (from SkipClean)
|
|
|
|
|
// In particular, rooms v3 event IDs are not urlsafe and can include '/' and because they
|
|
|
|
|
// are randomly generated it results in flakey tests.
|
|
|
|
|
// We need to be careful with media APIs if they read from a filesystem to make sure they
|
|
|
|
|
// are not inadvertently reading paths without cleaning, else this could introduce a
|
|
|
|
|
// directory traversal attack e.g /../../../etc/passwd
|
2021-01-26 13:56:20 +01:00
|
|
|
|
|
2018-01-02 11:26:56 +01:00
|
|
|
|
return &BaseDendrite{
|
2021-01-26 13:56:20 +01:00
|
|
|
|
ProcessContext: process.NewProcessContext(),
|
2020-08-13 13:16:37 +02:00
|
|
|
|
componentName: componentName,
|
|
|
|
|
UseHTTPAPIs: useHTTPAPIs,
|
|
|
|
|
tracerCloser: closer,
|
|
|
|
|
Cfg: cfg,
|
2022-07-11 15:31:31 +02:00
|
|
|
|
Caches: caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, enableMetrics),
|
2021-01-22 15:16:59 +01:00
|
|
|
|
DNSCache: dnsCache,
|
2020-08-13 13:16:37 +02:00
|
|
|
|
PublicClientAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicClientPathPrefix).Subrouter().UseEncodedPath(),
|
|
|
|
|
PublicFederationAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicFederationPathPrefix).Subrouter().UseEncodedPath(),
|
|
|
|
|
PublicKeyAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicKeyPathPrefix).Subrouter().UseEncodedPath(),
|
|
|
|
|
PublicMediaAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicMediaPathPrefix).Subrouter().UseEncodedPath(),
|
2021-09-10 11:05:31 +02:00
|
|
|
|
PublicWellKnownAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicWellKnownPrefix).Subrouter().UseEncodedPath(),
|
2020-08-13 13:16:37 +02:00
|
|
|
|
InternalAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
2022-03-25 14:25:15 +01:00
|
|
|
|
DendriteAdminMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.DendriteAdminPathPrefix).Subrouter().UseEncodedPath(),
|
|
|
|
|
SynapseAdminMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.SynapseAdminPathPrefix).Subrouter().UseEncodedPath(),
|
2022-05-09 15:15:24 +02:00
|
|
|
|
NATS: &jetstream.NATSInstance{},
|
2020-10-01 12:55:17 +02:00
|
|
|
|
apiHttpClient: &apiClient,
|
2022-05-03 17:35:06 +02:00
|
|
|
|
Database: db, // set if monolith with global connection pool only
|
|
|
|
|
DatabaseWriter: writer, // set if monolith with global connection pool only
|
2022-05-09 18:23:02 +02:00
|
|
|
|
EnableMetrics: enableMetrics,
|
2022-09-07 18:15:54 +02:00
|
|
|
|
Fulltext: fts,
|
2018-01-02 11:26:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close implements io.Closer
|
|
|
|
|
func (b *BaseDendrite) Close() error {
|
|
|
|
|
return b.tracerCloser.Close()
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 17:35:06 +02:00
|
|
|
|
// DatabaseConnection assists in setting up a database connection. It accepts
|
|
|
|
|
// the database properties and a new writer for the given component. If we're
|
|
|
|
|
// running in monolith mode with a global connection pool configured then we
|
|
|
|
|
// will return that connection, along with the global writer, effectively
|
|
|
|
|
// ignoring the options provided. Otherwise we'll open a new database connection
|
|
|
|
|
// using the supplied options and writer. Note that it's possible for the pointer
|
|
|
|
|
// receiver to be nil here – that's deliberate as some of the unit tests don't
|
|
|
|
|
// have a BaseDendrite and just want a connection with the supplied config
|
|
|
|
|
// without any pooling stuff.
|
|
|
|
|
func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, writer sqlutil.Writer) (*sql.DB, sqlutil.Writer, error) {
|
|
|
|
|
if dbProperties.ConnectionString != "" || b == nil {
|
|
|
|
|
// Open a new database connection using the supplied config.
|
|
|
|
|
db, err := sqlutil.Open(dbProperties, writer)
|
|
|
|
|
return db, writer, err
|
|
|
|
|
}
|
|
|
|
|
if b.Database != nil && b.DatabaseWriter != nil {
|
|
|
|
|
// Ignore the supplied config and return the global pool and
|
|
|
|
|
// writer.
|
|
|
|
|
return b.Database, b.DatabaseWriter, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, nil, fmt.Errorf("no database connections configured")
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 13:39:26 +02:00
|
|
|
|
// AppserviceHTTPClient returns the AppServiceInternalAPI for hitting the appservice component over HTTP.
|
|
|
|
|
func (b *BaseDendrite) AppserviceHTTPClient() appserviceAPI.AppServiceInternalAPI {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
a, err := asinthttp.NewAppserviceClient(b.Cfg.AppServiceURL(), b.apiHttpClient)
|
2020-04-03 12:40:50 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
logrus.WithError(err).Panic("CreateHTTPAppServiceAPIs failed")
|
|
|
|
|
}
|
|
|
|
|
return a
|
2018-07-17 16:36:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 16:43:07 +02:00
|
|
|
|
// RoomserverHTTPClient returns RoomserverInternalAPI for hitting the roomserver over HTTP.
|
|
|
|
|
func (b *BaseDendrite) RoomserverHTTPClient() roomserverAPI.RoomserverInternalAPI {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
rsAPI, err := rsinthttp.NewRoomserverClient(b.Cfg.RoomServerURL(), b.apiHttpClient, b.Caches)
|
2020-04-03 12:40:50 +02:00
|
|
|
|
if err != nil {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
logrus.WithError(err).Panic("RoomserverHTTPClient failed", b.apiHttpClient)
|
2020-04-03 12:40:50 +02:00
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
|
return rsAPI
|
2018-01-02 11:26:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 15:10:55 +02:00
|
|
|
|
// UserAPIClient returns UserInternalAPI for hitting the userapi over HTTP.
|
|
|
|
|
func (b *BaseDendrite) UserAPIClient() userapi.UserInternalAPI {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
userAPI, err := userapiinthttp.NewUserAPIClient(b.Cfg.UserAPIURL(), b.apiHttpClient)
|
2020-06-16 15:10:55 +02:00
|
|
|
|
if err != nil {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
logrus.WithError(err).Panic("UserAPIClient failed", b.apiHttpClient)
|
2020-06-16 15:10:55 +02:00
|
|
|
|
}
|
|
|
|
|
return userAPI
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 11:45:23 +01:00
|
|
|
|
// FederationAPIHTTPClient returns FederationInternalAPI for hitting
|
|
|
|
|
// the federation API server over HTTP
|
|
|
|
|
func (b *BaseDendrite) FederationAPIHTTPClient() federationAPI.FederationInternalAPI {
|
|
|
|
|
f, err := federationIntHTTP.NewFederationAPIClient(b.Cfg.FederationAPIURL(), b.apiHttpClient, b.Caches)
|
2020-05-27 11:19:24 +02:00
|
|
|
|
if err != nil {
|
2021-11-24 11:45:23 +01:00
|
|
|
|
logrus.WithError(err).Panic("FederationAPIHTTPClient failed", b.apiHttpClient)
|
2020-05-27 11:19:24 +02:00
|
|
|
|
}
|
|
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 17:02:35 +02:00
|
|
|
|
// KeyServerHTTPClient returns KeyInternalAPI for hitting the key server over HTTP
|
|
|
|
|
func (b *BaseDendrite) KeyServerHTTPClient() keyserverAPI.KeyInternalAPI {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
f, err := keyinthttp.NewKeyServerClient(b.Cfg.KeyServerURL(), b.apiHttpClient)
|
2020-07-13 17:02:35 +02:00
|
|
|
|
if err != nil {
|
2020-10-01 12:55:17 +02:00
|
|
|
|
logrus.WithError(err).Panic("KeyServerHTTPClient failed", b.apiHttpClient)
|
2020-07-13 17:02:35 +02:00
|
|
|
|
}
|
|
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 12:40:53 +01:00
|
|
|
|
// PushGatewayHTTPClient returns a new client for interacting with (external) Push Gateways.
|
|
|
|
|
func (b *BaseDendrite) PushGatewayHTTPClient() pushgateway.Client {
|
|
|
|
|
return pushgateway.NewHTTPClient(b.Cfg.UserAPI.PushGatewayDisableTLSValidation)
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 12:55:17 +02:00
|
|
|
|
// CreateClient creates a new client (normally used for media fetch requests).
|
|
|
|
|
// Should only be called once per component.
|
|
|
|
|
func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client {
|
2020-12-02 16:10:03 +01:00
|
|
|
|
if b.Cfg.Global.DisableFederation {
|
2021-01-22 17:09:05 +01:00
|
|
|
|
return gomatrixserverlib.NewClient(
|
|
|
|
|
gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
opts := []gomatrixserverlib.ClientOption{
|
2021-11-24 11:45:23 +01:00
|
|
|
|
gomatrixserverlib.WithSkipVerify(b.Cfg.FederationAPI.DisableTLSValidation),
|
2022-05-05 15:06:05 +02:00
|
|
|
|
gomatrixserverlib.WithWellKnownSRVLookups(true),
|
2020-12-02 16:10:03 +01:00
|
|
|
|
}
|
2021-01-22 15:16:59 +01:00
|
|
|
|
if b.Cfg.Global.DNSCache.Enabled {
|
2021-01-22 17:09:05 +01:00
|
|
|
|
opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache))
|
2021-01-22 15:16:59 +01:00
|
|
|
|
}
|
2021-01-22 17:09:05 +01:00
|
|
|
|
client := gomatrixserverlib.NewClient(opts...)
|
2020-10-01 12:55:17 +02:00
|
|
|
|
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
|
|
|
|
return client
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 11:26:56 +01:00
|
|
|
|
// CreateFederationClient creates a new federation client. Should only be called
|
|
|
|
|
// once per component.
|
|
|
|
|
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
2022-11-15 16:05:23 +01:00
|
|
|
|
identities := b.Cfg.Global.SigningIdentities()
|
2020-12-02 16:10:03 +01:00
|
|
|
|
if b.Cfg.Global.DisableFederation {
|
2021-01-22 17:09:05 +01:00
|
|
|
|
return gomatrixserverlib.NewFederationClient(
|
2022-11-15 16:05:23 +01:00
|
|
|
|
identities, gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
2020-12-02 16:10:03 +01:00
|
|
|
|
)
|
|
|
|
|
}
|
2021-01-22 17:09:05 +01:00
|
|
|
|
opts := []gomatrixserverlib.ClientOption{
|
|
|
|
|
gomatrixserverlib.WithTimeout(time.Minute * 5),
|
2021-11-24 11:45:23 +01:00
|
|
|
|
gomatrixserverlib.WithSkipVerify(b.Cfg.FederationAPI.DisableTLSValidation),
|
2022-09-20 18:17:44 +02:00
|
|
|
|
gomatrixserverlib.WithKeepAlives(!b.Cfg.FederationAPI.DisableHTTPKeepalives),
|
2021-01-22 17:09:05 +01:00
|
|
|
|
}
|
2021-01-22 15:16:59 +01:00
|
|
|
|
if b.Cfg.Global.DNSCache.Enabled {
|
2021-01-22 17:09:05 +01:00
|
|
|
|
opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache))
|
2021-01-22 15:16:59 +01:00
|
|
|
|
}
|
2021-01-22 17:09:05 +01:00
|
|
|
|
client := gomatrixserverlib.NewFederationClient(
|
2022-11-15 16:05:23 +01:00
|
|
|
|
identities, opts...,
|
2018-01-02 11:26:56 +01:00
|
|
|
|
)
|
2020-10-01 12:55:17 +02:00
|
|
|
|
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
|
|
|
|
return client
|
2018-01-02 11:26:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 12:34:27 +02:00
|
|
|
|
func (b *BaseDendrite) configureHTTPErrors() {
|
|
|
|
|
notAllowedHandler := func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
|
|
_, _ = w.Write([]byte(fmt.Sprintf("405 %s not allowed on this endpoint", r.Method)))
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 16:50:22 +02:00
|
|
|
|
clientNotFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
_, _ = w.Write([]byte(`{"errcode":"M_UNRECOGNIZED","error":"Unrecognized request"}`)) // nolint:misspell
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 12:34:27 +02:00
|
|
|
|
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.NotFoundHandler())
|
|
|
|
|
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
|
|
|
|
|
|
|
|
|
for _, router := range []*mux.Router{
|
2022-09-27 16:50:22 +02:00
|
|
|
|
b.PublicMediaAPIMux, b.DendriteAdminMux,
|
|
|
|
|
b.SynapseAdminMux, b.PublicWellKnownAPIMux,
|
2022-08-01 12:34:27 +02:00
|
|
|
|
} {
|
|
|
|
|
router.NotFoundHandler = notFoundCORSHandler
|
|
|
|
|
router.MethodNotAllowedHandler = notAllowedCORSHandler
|
|
|
|
|
}
|
2022-09-27 16:50:22 +02:00
|
|
|
|
|
|
|
|
|
// Special case so that we don't upset clients on the CS API.
|
|
|
|
|
b.PublicClientAPIMux.NotFoundHandler = http.HandlerFunc(clientNotFoundHandler)
|
|
|
|
|
b.PublicClientAPIMux.MethodNotAllowedHandler = http.HandlerFunc(clientNotFoundHandler)
|
2022-08-01 12:34:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-01 11:45:15 +01:00
|
|
|
|
func (b *BaseDendrite) ConfigureAdminEndpoints() {
|
|
|
|
|
b.DendriteAdminMux.HandleFunc("/monitor/up", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(200)
|
|
|
|
|
})
|
|
|
|
|
b.DendriteAdminMux.HandleFunc("/monitor/health", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if isDegraded, reasons := b.ProcessContext.IsDegraded(); isDegraded {
|
|
|
|
|
w.WriteHeader(503)
|
|
|
|
|
_ = json.NewEncoder(w).Encode(struct {
|
|
|
|
|
Warnings []string `json:"warnings"`
|
|
|
|
|
}{
|
|
|
|
|
Warnings: reasons,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.WriteHeader(200)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 11:26:56 +01:00
|
|
|
|
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
|
|
|
|
// ApiMux under /api/ and adds a prometheus handler under /metrics.
|
2020-08-13 13:16:37 +02:00
|
|
|
|
func (b *BaseDendrite) SetupAndServeHTTP(
|
|
|
|
|
internalHTTPAddr, externalHTTPAddr config.HTTPAddress,
|
|
|
|
|
certFile, keyFile *string,
|
|
|
|
|
) {
|
2022-08-30 13:59:13 +02:00
|
|
|
|
// Manually unlocked right before actually serving requests,
|
|
|
|
|
// as we don't return from this method (defer doesn't work).
|
|
|
|
|
b.startupLock.Lock()
|
2020-08-13 13:16:37 +02:00
|
|
|
|
internalAddr, _ := internalHTTPAddr.Address()
|
|
|
|
|
externalAddr, _ := externalHTTPAddr.Address()
|
|
|
|
|
|
2020-10-07 17:59:22 +02:00
|
|
|
|
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
|
|
|
|
internalRouter := externalRouter
|
2020-08-13 13:16:37 +02:00
|
|
|
|
|
2020-10-07 17:59:22 +02:00
|
|
|
|
externalServ := &http.Server{
|
|
|
|
|
Addr: string(externalAddr),
|
2020-04-20 18:42:34 +02:00
|
|
|
|
WriteTimeout: HTTPServerTimeout,
|
2020-10-07 17:59:22 +02:00
|
|
|
|
Handler: externalRouter,
|
2022-04-27 16:01:57 +02:00
|
|
|
|
BaseContext: func(_ net.Listener) context.Context {
|
|
|
|
|
return b.ProcessContext.Context()
|
|
|
|
|
},
|
2020-08-13 13:16:37 +02:00
|
|
|
|
}
|
2020-10-07 17:59:22 +02:00
|
|
|
|
internalServ := externalServ
|
|
|
|
|
|
|
|
|
|
if internalAddr != NoListener && externalAddr != internalAddr {
|
2020-10-20 18:13:12 +02:00
|
|
|
|
// H2C allows us to accept HTTP/2 connections without TLS
|
|
|
|
|
// encryption. Since we don't currently require any form of
|
|
|
|
|
// authentication or encryption on these internal HTTP APIs,
|
|
|
|
|
// H2C gives us all of the advantages of HTTP/2 (such as
|
|
|
|
|
// stream multiplexing and avoiding head-of-line blocking)
|
|
|
|
|
// without enabling TLS.
|
|
|
|
|
internalH2S := &http2.Server{}
|
2020-10-07 17:59:22 +02:00
|
|
|
|
internalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath()
|
|
|
|
|
internalServ = &http.Server{
|
|
|
|
|
Addr: string(internalAddr),
|
2020-10-20 18:13:12 +02:00
|
|
|
|
Handler: h2c.NewHandler(internalRouter, internalH2S),
|
2022-04-27 16:01:57 +02:00
|
|
|
|
BaseContext: func(_ net.Listener) context.Context {
|
|
|
|
|
return b.ProcessContext.Context()
|
|
|
|
|
},
|
2020-08-13 13:16:37 +02:00
|
|
|
|
}
|
2020-04-20 18:42:34 +02:00
|
|
|
|
}
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
2022-08-01 12:34:27 +02:00
|
|
|
|
b.configureHTTPErrors()
|
|
|
|
|
|
2020-08-13 13:16:37 +02:00
|
|
|
|
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
|
|
|
|
if b.Cfg.Global.Metrics.Enabled {
|
|
|
|
|
internalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth))
|
|
|
|
|
}
|
2018-01-02 11:26:56 +01:00
|
|
|
|
|
2022-12-01 11:45:15 +01:00
|
|
|
|
b.ConfigureAdminEndpoints()
|
2022-03-25 14:25:15 +01:00
|
|
|
|
|
2021-03-24 11:25:24 +01:00
|
|
|
|
var clientHandler http.Handler
|
|
|
|
|
clientHandler = b.PublicClientAPIMux
|
|
|
|
|
if b.Cfg.Global.Sentry.Enabled {
|
|
|
|
|
sentryHandler := sentryhttp.New(sentryhttp.Options{
|
|
|
|
|
Repanic: true,
|
|
|
|
|
})
|
|
|
|
|
clientHandler = sentryHandler.Handle(b.PublicClientAPIMux)
|
|
|
|
|
}
|
|
|
|
|
var federationHandler http.Handler
|
|
|
|
|
federationHandler = b.PublicFederationAPIMux
|
|
|
|
|
if b.Cfg.Global.Sentry.Enabled {
|
|
|
|
|
sentryHandler := sentryhttp.New(sentryhttp.Options{
|
|
|
|
|
Repanic: true,
|
|
|
|
|
})
|
|
|
|
|
federationHandler = sentryHandler.Handle(b.PublicFederationAPIMux)
|
|
|
|
|
}
|
2022-03-25 14:25:15 +01:00
|
|
|
|
internalRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(b.DendriteAdminMux)
|
2021-03-24 11:25:24 +01:00
|
|
|
|
externalRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(clientHandler)
|
2020-12-02 16:10:03 +01:00
|
|
|
|
if !b.Cfg.Global.DisableFederation {
|
|
|
|
|
externalRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(b.PublicKeyAPIMux)
|
2021-03-24 11:25:24 +01:00
|
|
|
|
externalRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(federationHandler)
|
2020-12-02 16:10:03 +01:00
|
|
|
|
}
|
2022-03-25 14:25:15 +01:00
|
|
|
|
externalRouter.PathPrefix(httputil.SynapseAdminPathPrefix).Handler(b.SynapseAdminMux)
|
2020-08-13 13:16:37 +02:00
|
|
|
|
externalRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(b.PublicMediaAPIMux)
|
2021-09-10 11:05:31 +02:00
|
|
|
|
externalRouter.PathPrefix(httputil.PublicWellKnownPrefix).Handler(b.PublicWellKnownAPIMux)
|
2020-08-13 13:16:37 +02:00
|
|
|
|
|
2022-08-30 13:59:13 +02:00
|
|
|
|
b.startupLock.Unlock()
|
2020-10-07 17:59:22 +02:00
|
|
|
|
if internalAddr != NoListener && internalAddr != externalAddr {
|
|
|
|
|
go func() {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
var internalShutdown atomic.Bool // RegisterOnShutdown can be called more than once
|
2020-10-07 17:59:22 +02:00
|
|
|
|
logrus.Infof("Starting internal %s listener on %s", b.componentName, internalServ.Addr)
|
2021-01-26 13:56:20 +01:00
|
|
|
|
b.ProcessContext.ComponentStarted()
|
|
|
|
|
internalServ.RegisterOnShutdown(func() {
|
2022-09-20 16:01:19 +02:00
|
|
|
|
if internalShutdown.CompareAndSwap(false, true) {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
b.ProcessContext.ComponentFinished()
|
|
|
|
|
logrus.Infof("Stopped internal HTTP listener")
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-10-07 17:59:22 +02:00
|
|
|
|
if certFile != nil && keyFile != nil {
|
|
|
|
|
if err := internalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
if err != http.ErrServerClosed {
|
|
|
|
|
logrus.WithError(err).Fatal("failed to serve HTTPS")
|
|
|
|
|
}
|
2020-10-07 17:59:22 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if err := internalServ.ListenAndServe(); err != nil {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
if err != http.ErrServerClosed {
|
|
|
|
|
logrus.WithError(err).Fatal("failed to serve HTTP")
|
|
|
|
|
}
|
2020-10-07 17:59:22 +02:00
|
|
|
|
}
|
2020-08-13 13:16:37 +02:00
|
|
|
|
}
|
2020-10-07 17:59:22 +02:00
|
|
|
|
logrus.Infof("Stopped internal %s listener on %s", b.componentName, internalServ.Addr)
|
|
|
|
|
}()
|
|
|
|
|
}
|
2020-08-13 13:16:37 +02:00
|
|
|
|
|
2020-10-07 17:59:22 +02:00
|
|
|
|
if externalAddr != NoListener {
|
2020-08-13 13:16:37 +02:00
|
|
|
|
go func() {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
var externalShutdown atomic.Bool // RegisterOnShutdown can be called more than once
|
2020-10-07 17:59:22 +02:00
|
|
|
|
logrus.Infof("Starting external %s listener on %s", b.componentName, externalServ.Addr)
|
2021-01-26 13:56:20 +01:00
|
|
|
|
b.ProcessContext.ComponentStarted()
|
|
|
|
|
externalServ.RegisterOnShutdown(func() {
|
2022-09-20 16:01:19 +02:00
|
|
|
|
if externalShutdown.CompareAndSwap(false, true) {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
b.ProcessContext.ComponentFinished()
|
|
|
|
|
logrus.Infof("Stopped external HTTP listener")
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-08-13 13:16:37 +02:00
|
|
|
|
if certFile != nil && keyFile != nil {
|
2020-08-13 19:27:19 +02:00
|
|
|
|
if err := externalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
if err != http.ErrServerClosed {
|
|
|
|
|
logrus.WithError(err).Fatal("failed to serve HTTPS")
|
|
|
|
|
}
|
2020-08-13 13:16:37 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-08-13 19:27:19 +02:00
|
|
|
|
if err := externalServ.ListenAndServe(); err != nil {
|
2021-01-26 13:56:20 +01:00
|
|
|
|
if err != http.ErrServerClosed {
|
|
|
|
|
logrus.WithError(err).Fatal("failed to serve HTTP")
|
|
|
|
|
}
|
2020-08-13 13:16:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-07 17:59:22 +02:00
|
|
|
|
logrus.Infof("Stopped external %s listener on %s", b.componentName, externalServ.Addr)
|
2020-08-13 13:16:37 +02:00
|
|
|
|
}()
|
2018-01-02 11:26:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-27 14:36:40 +02:00
|
|
|
|
minwinsvc.SetOnExit(b.ProcessContext.ShutdownDendrite)
|
2022-04-27 16:29:49 +02:00
|
|
|
|
<-b.ProcessContext.WaitForShutdown()
|
2022-04-27 17:04:11 +02:00
|
|
|
|
|
2022-04-27 16:29:49 +02:00
|
|
|
|
logrus.Infof("Stopping HTTP listeners")
|
|
|
|
|
_ = internalServ.Shutdown(context.Background())
|
|
|
|
|
_ = externalServ.Shutdown(context.Background())
|
2021-01-26 13:56:20 +01:00
|
|
|
|
logrus.Infof("Stopped HTTP listeners")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *BaseDendrite) WaitForShutdown() {
|
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
2022-04-27 14:36:40 +02:00
|
|
|
|
select {
|
|
|
|
|
case <-sigs:
|
|
|
|
|
case <-b.ProcessContext.WaitForShutdown():
|
|
|
|
|
}
|
2021-01-26 13:56:20 +01:00
|
|
|
|
signal.Reset(syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
|
|
logrus.Warnf("Shutdown signal received")
|
|
|
|
|
|
|
|
|
|
b.ProcessContext.ShutdownDendrite()
|
|
|
|
|
b.ProcessContext.WaitForComponentsToFinish()
|
2021-03-24 11:25:24 +01:00
|
|
|
|
if b.Cfg.Global.Sentry.Enabled {
|
|
|
|
|
if !sentry.Flush(time.Second * 5) {
|
|
|
|
|
logrus.Warnf("failed to flush all Sentry events!")
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-26 13:56:20 +01:00
|
|
|
|
|
|
|
|
|
logrus.Warnf("Dendrite is exiting now")
|
2018-01-02 11:26:56 +01:00
|
|
|
|
}
|