File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -319,7 +319,7 @@ func (br *Bridge) Stop() {
319319func (br * Bridge ) stop (isRunOnce bool ) {
320320 br .Log .Info ().Msg ("Shutting down bridge" )
321321 br .stopBackfillQueue .Set ()
322- br .Matrix .Stop ()
322+ br .Matrix .PreStop ()
323323 if ! isRunOnce {
324324 br .cacheLock .Lock ()
325325 var wg sync.WaitGroup
@@ -330,6 +330,7 @@ func (br *Bridge) stop(isRunOnce bool) {
330330 br .cacheLock .Unlock ()
331331 wg .Wait ()
332332 }
333+ br .Matrix .Stop ()
333334 if stopNet , ok := br .Network .(StoppableNetwork ); ok {
334335 stopNet .Stop ()
335336 }
Original file line number Diff line number Diff line change @@ -233,13 +233,37 @@ func (br *Connector) GetCapabilities() *bridgev2.MatrixCapabilities {
233233 return br .Capabilities
234234}
235235
236- func (br * Connector ) Stop () {
236+ func sendStopSignal (ch chan struct {}) {
237+ if ch != nil {
238+ select {
239+ case ch <- struct {}{}:
240+ default :
241+ }
242+ }
243+ }
244+
245+ func (br * Connector ) PreStop () {
237246 br .stopping = true
238247 br .AS .Stop ()
248+ if stopWebsocket := br .AS .StopWebsocket ; stopWebsocket != nil {
249+ stopWebsocket (appservice .ErrWebsocketManualStop )
250+ }
251+ sendStopSignal (br .wsStopPinger )
252+ sendStopSignal (br .wsShortCircuitReconnectBackoff )
253+ }
254+
255+ func (br * Connector ) Stop () {
239256 br .EventProcessor .Stop ()
240257 if br .Crypto != nil {
241258 br .Crypto .Stop ()
242259 }
260+ if wsStopChan := br .wsStopped ; wsStopChan != nil {
261+ select {
262+ case <- wsStopChan :
263+ case <- time .After (4 * time .Second ):
264+ br .Log .Warn ().Msg ("Timed out waiting for websocket to close" )
265+ }
266+ }
243267}
244268
245269var MinSpecVersion = mautrix .SpecV14
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ type MatrixCapabilities struct {
3131type MatrixConnector interface {
3232 Init (* Bridge )
3333 Start (ctx context.Context ) error
34+ PreStop ()
3435 Stop ()
3536
3637 GetCapabilities () * MatrixCapabilities
You can’t perform that action at this time.
0 commit comments