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() {
319
319
func (br * Bridge ) stop (isRunOnce bool ) {
320
320
br .Log .Info ().Msg ("Shutting down bridge" )
321
321
br .stopBackfillQueue .Set ()
322
- br .Matrix .Stop ()
322
+ br .Matrix .PreStop ()
323
323
if ! isRunOnce {
324
324
br .cacheLock .Lock ()
325
325
var wg sync.WaitGroup
@@ -330,6 +330,7 @@ func (br *Bridge) stop(isRunOnce bool) {
330
330
br .cacheLock .Unlock ()
331
331
wg .Wait ()
332
332
}
333
+ br .Matrix .Stop ()
333
334
if stopNet , ok := br .Network .(StoppableNetwork ); ok {
334
335
stopNet .Stop ()
335
336
}
Original file line number Diff line number Diff line change @@ -233,13 +233,37 @@ func (br *Connector) GetCapabilities() *bridgev2.MatrixCapabilities {
233
233
return br .Capabilities
234
234
}
235
235
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 () {
237
246
br .stopping = true
238
247
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 () {
239
256
br .EventProcessor .Stop ()
240
257
if br .Crypto != nil {
241
258
br .Crypto .Stop ()
242
259
}
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
+ }
243
267
}
244
268
245
269
var MinSpecVersion = mautrix .SpecV14
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ type MatrixCapabilities struct {
31
31
type MatrixConnector interface {
32
32
Init (* Bridge )
33
33
Start (ctx context.Context ) error
34
+ PreStop ()
34
35
Stop ()
35
36
36
37
GetCapabilities () * MatrixCapabilities
You can’t perform that action at this time.
0 commit comments