Skip to content

Commit

Permalink
Handle MessageExpiryInterval early enough for retained messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dariopb committed Dec 19, 2024
1 parent 8f52b89 commit 5aeec3b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5aeec3b

Please sign in to comment.