From 5aeec3b2a899c6f4d654533c138b1d33d5ca5a20 Mon Sep 17 00:00:00 2001 From: Dario Bazan Date: Wed, 18 Dec 2024 16:29:11 -0800 Subject: [PATCH] Handle MessageExpiryInterval early enough for retained messages --- server.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 5bcd5cc7..1c2eaeed 100644 --- a/server.go +++ b/server.go @@ -885,6 +885,11 @@ func (s *Server) processPublish(cl *Client, pk packets.Packet) error { pk.Origin = cl.ID pk.Created = time.Now().Unix() + pk.Expiry = pk.Created + s.Options.Capabilities.MaximumMessageExpiryInterval + if pk.Properties.MessageExpiryInterval > 0 { + pk.Expiry = pk.Created + int64(pk.Properties.MessageExpiryInterval) + } + if !cl.Net.Inline { if pki, ok := cl.State.Inflight.Get(pk.PacketID); ok { if pki.FixedHeader.Type == packets.Pubrec { // [MQTT-4.3.3-10] @@ -986,9 +991,11 @@ func (s *Server) publishToSubscribers(pk packets.Packet) { pk.Created = time.Now().Unix() } - pk.Expiry = pk.Created + s.Options.Capabilities.MaximumMessageExpiryInterval - if pk.Properties.MessageExpiryInterval > 0 { - pk.Expiry = pk.Created + int64(pk.Properties.MessageExpiryInterval) + if pk.Expiry == 0 { + pk.Expiry = pk.Created + s.Options.Capabilities.MaximumMessageExpiryInterval + if pk.Properties.MessageExpiryInterval > 0 { + pk.Expiry = pk.Created + int64(pk.Properties.MessageExpiryInterval) + } } subscribers := s.Topics.Subscribers(pk.TopicName)