Handle StreamReplaced errors

This commit is contained in:
Tulir Asokan 2022-09-06 15:38:47 -04:00
parent b923a39d76
commit 60506593e5
6 changed files with 18 additions and 4 deletions

View file

@ -121,7 +121,8 @@ type BridgeConfig struct {
DisableStatusBroadcastSend bool `yaml:"disable_status_broadcast_send"` DisableStatusBroadcastSend bool `yaml:"disable_status_broadcast_send"`
DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"` DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"`
DisableBridgeAlerts bool `yaml:"disable_bridge_alerts"` DisableBridgeAlerts bool `yaml:"disable_bridge_alerts"`
CrashOnStreamReplaced bool `yaml:"crash_on_stream_replaced"`
CommandPrefix string `yaml:"command_prefix"` CommandPrefix string `yaml:"command_prefix"`

View file

@ -89,6 +89,7 @@ func DoUpgrade(helper *up.Helper) {
helper.Copy(up.Bool, "bridge", "federate_rooms") helper.Copy(up.Bool, "bridge", "federate_rooms")
helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups") helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups")
helper.Copy(up.Bool, "bridge", "disable_bridge_alerts") helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
helper.Copy(up.Bool, "bridge", "crash_on_stream_replaced")
helper.Copy(up.Bool, "bridge", "url_previews") helper.Copy(up.Bool, "bridge", "url_previews")
helper.Copy(up.Bool, "bridge", "caption_in_message") helper.Copy(up.Bool, "bridge", "caption_in_message")
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after") helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after")

View file

@ -274,6 +274,9 @@ bridge:
# Should the bridge never send alerts to the bridge management room? # Should the bridge never send alerts to the bridge management room?
# These are mostly things like the user being logged out. # These are mostly things like the user being logged out.
disable_bridge_alerts: false disable_bridge_alerts: false
# Should the bridge stop if the WhatsApp server says another user connected with the same session?
# This is only safe on single-user bridges.
crash_on_stream_replaced: false
# Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview, # Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview,
# and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews` # and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews`
# key in the event content even if this is disabled. # key in the event content even if this is disabled.

2
go.mod
View file

@ -16,7 +16,7 @@ require (
golang.org/x/net v0.0.0-20220812174116-3211cb980234 golang.org/x/net v0.0.0-20220812174116-3211cb980234
google.golang.org/protobuf v1.28.1 google.golang.org/protobuf v1.28.1
maunium.net/go/maulogger/v2 v2.3.2 maunium.net/go/maulogger/v2 v2.3.2
maunium.net/go/mautrix v0.12.1-0.20220825085831-88c1e0dc4593 maunium.net/go/mautrix v0.12.1-0.20220906193443-f700a94f80b7
) )
require ( require (

4
go.sum
View file

@ -100,5 +100,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0= maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A= maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
maunium.net/go/mautrix v0.12.1-0.20220825085831-88c1e0dc4593 h1:HsTKCkpyDnJg0rOjzynChCAgK9NrICXEqMRaRiz43fI= maunium.net/go/mautrix v0.12.1-0.20220906193443-f700a94f80b7 h1:7HXfRjWHoZ9ISo9K19yR1j8WSrbn1q2Sd0eqdAQXxVg=
maunium.net/go/mautrix v0.12.1-0.20220825085831-88c1e0dc4593/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE= maunium.net/go/mautrix v0.12.1-0.20220906193443-f700a94f80b7/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=

View file

@ -815,6 +815,15 @@ func (user *User) HandleEvent(event interface{}) {
} }
go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: message}) go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: message})
user.bridge.Metrics.TrackConnectionState(user.JID, false) user.bridge.Metrics.TrackConnectionState(user.JID, false)
case *events.StreamReplaced:
if user.bridge.Config.Bridge.CrashOnStreamReplaced {
user.log.Infofln("Stopping bridge due to StreamReplaced event")
user.bridge.ManualStop(60)
} else {
go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: "Stream replaced"})
user.bridge.Metrics.TrackConnectionState(user.JID, false)
user.sendMarkdownBridgeAlert("The bridge was started in another location. Use `reconnect` to reconnect this one.")
}
case *events.ConnectFailure: case *events.ConnectFailure:
go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: fmt.Sprintf("Unknown connection failure: %s", v.Reason)}) go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: fmt.Sprintf("Unknown connection failure: %s", v.Reason)})
user.bridge.Metrics.TrackConnectionState(user.JID, false) user.bridge.Metrics.TrackConnectionState(user.JID, false)