mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 17:33:48 +01:00
Extend message handling timeout for scheduled messages
This commit is contained in:
parent
794975eaa0
commit
574d6f47c3
3 changed files with 17 additions and 8 deletions
2
go.mod
2
go.mod
|
@ -15,7 +15,7 @@ require (
|
||||||
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e
|
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e
|
||||||
google.golang.org/protobuf v1.28.0
|
google.golang.org/protobuf v1.28.0
|
||||||
maunium.net/go/maulogger/v2 v2.3.2
|
maunium.net/go/maulogger/v2 v2.3.2
|
||||||
maunium.net/go/mautrix v0.11.1-0.20220711103551-a5a1e7e5df84
|
maunium.net/go/mautrix v0.11.1-0.20220711120626-546455a7c0ef
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -108,5 +108,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.11.1-0.20220711103551-a5a1e7e5df84 h1:Zhx97T0nWGKF8phXeQ/uws6fnntc9c8WIvQ4yh/fgPU=
|
maunium.net/go/mautrix v0.11.1-0.20220711120626-546455a7c0ef h1:XCq8B290fN3IsoLhng/+I3puv6FoW9SanDJqvOJ0O+4=
|
||||||
maunium.net/go/mautrix v0.11.1-0.20220711103551-a5a1e7e5df84/go.mod h1:85mjebfgKX7jjca7XNKTt7lHueX3YQsFUU+5o/FxpTw=
|
maunium.net/go/mautrix v0.11.1-0.20220711120626-546455a7c0ef/go.mod h1:85mjebfgKX7jjca7XNKTt7lHueX3YQsFUU+5o/FxpTw=
|
||||||
|
|
19
portal.go
19
portal.go
|
@ -3135,13 +3135,22 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
||||||
portal.log.Debugfln("Received message %s from %s (age: %s)", evt.ID, evt.Sender, messageAge)
|
portal.log.Debugfln("Received message %s from %s (age: %s)", evt.ID, evt.Sender, messageAge)
|
||||||
}
|
}
|
||||||
|
|
||||||
if portal.bridge.Config.Bridge.MessageHandlingTimeout.ErrorAfter > 0 {
|
errorAfter := portal.bridge.Config.Bridge.MessageHandlingTimeout.ErrorAfter
|
||||||
remainingTime := portal.bridge.Config.Bridge.MessageHandlingTimeout.ErrorAfter - messageAge
|
deadline := portal.bridge.Config.Bridge.MessageHandlingTimeout.Deadline
|
||||||
|
isScheduled, _ := evt.Content.Raw["com.beeper.scheduled"].(bool)
|
||||||
|
if isScheduled {
|
||||||
|
portal.log.Debugfln("%s is a scheduled message, extending handling timeouts", evt.ID)
|
||||||
|
errorAfter *= 10
|
||||||
|
deadline *= 10
|
||||||
|
}
|
||||||
|
|
||||||
|
if errorAfter > 0 {
|
||||||
|
remainingTime := errorAfter - messageAge
|
||||||
if remainingTime < 0 {
|
if remainingTime < 0 {
|
||||||
go ms.sendMessageMetrics(evt, errTimeoutBeforeHandling, "Timeout handling", true)
|
go ms.sendMessageMetrics(evt, errTimeoutBeforeHandling, "Timeout handling", true)
|
||||||
return
|
return
|
||||||
} else if remainingTime < 1*time.Second {
|
} else if remainingTime < 1*time.Second {
|
||||||
portal.log.Warnfln("Message %s was delayed before reaching the bridge, only have %s (of %s timeout) until delay warning", evt.ID, remainingTime, portal.bridge.Config.Bridge.MessageHandlingTimeout.ErrorAfter)
|
portal.log.Warnfln("Message %s was delayed before reaching the bridge, only have %s (of %s timeout) until delay warning", evt.ID, remainingTime, errorAfter)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(remainingTime)
|
time.Sleep(remainingTime)
|
||||||
|
@ -3150,9 +3159,9 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
if portal.bridge.Config.Bridge.MessageHandlingTimeout.Deadline > 0 {
|
if deadline > 0 {
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
ctx, cancel = context.WithTimeout(ctx, portal.bridge.Config.Bridge.MessageHandlingTimeout.Deadline)
|
ctx, cancel = context.WithTimeout(ctx, deadline)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue