processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6k stars 1.5k forks source link

items order in a page is wrong with Pubsub RSM when `<before/>` is used #3621

Closed goffi-contrib closed 3 years ago

goffi-contrib commented 3 years ago

Environment

Bug description

Hello,

this bug is related to https://github.com/processone/ejabberd/issues/3618 I've seen it after publishing, so the fix to #3618 may have fixed this one too, in which case this one can be closed and sorry for the noise :).

This has been seen on a running instance of Movim. When I request a page of items of a blog with RSM items are returned in non chronological order, while they should be in chronological order.

Note that this issue happens when <before/> is used to get last page, but if we request the first page with only <max>3</max>, then the items are in expected order.

Here is the relevant stream capture:

<iq id="H_134" type="get" to="edhelas@movim.eu">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <items node="urn:xmpp:microblog:0"/>
    <set xmlns="http://jabber.org/protocol/rsm">
      <max>3</max>
      <before/>
    </set>
  </pubsub>
</iq>

<iq xmlns="jabber:client" to="goffi@jabber.fr/SàT" type="result" id="H_134" from="edhelas@movim.eu" xml:lang="en">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <set xmlns="http://jabber.org/protocol/rsm">
      <count>167</count>
      <first index="0">2021-05-27T22:41:35.266278Z</first>
      <last>2021-04-04T15:18:12.443634Z</last>
    </set>
    <items node="urn:xmpp:microblog:0">
      <item id="59d860ab-d7c8-477c-bb4b-86924485cbbb">
        <entry xmlns="http://www.w3.org/2005/Atom">
          <id>59d860ab-d7c8-477c-bb4b-86924485cbbb</id>
          [IRRELEVANT, REDACTED FOR READABILITY]
          <published>2021-05-27T22:41:35+00:00</published>
          [IRRELEVANT, REDACTED FOR READABILITY]
          <updated>2021-05-27T22:42:51+00:00</updated>
        </entry>
      </item>
      <item id="a-simple-raspberry-pi-for-your-complete-audio-system-f58YrE">
        <entry xmlns="http://www.w3.org/2005/Atom">
          <id>a-simple-raspberry-pi-for-your-complete-audio-system-f58YrE</id>
          [IRRELEVANT, REDACTED FOR READABILITY]
          <published>2021-05-18T21:18:41+00:00</published>
          <category term="RaspberryPi"/>
          <updated>2021-05-19T22:05:58+00:00</updated>
        </entry>
      </item>
      <item id="ebd1c7cd-2758-48ed-8554-6d0034944089">
        <entry xmlns="http://www.w3.org/2005/Atom">
          <id>ebd1c7cd-2758-48ed-8554-6d0034944089</id>
          [IRRELEVANT, REDACTED FOR READABILITY]
          <published>2021-04-04T15:18:12+00:00</published>
          [IRRELEVANT, REDACTED FOR READABILITY]
          <updated>2021-04-04T15:37:29+00:00</updated>
        </entry>
      </item>
    </items>
  </pubsub>
</iq>

In addition to the index issue described and fixed with #3618, the item are returned in anti-chronological order, and we have:

      <first index="0">2021-05-27T22:41:35.266278Z</first>
      <last>2021-04-04T15:18:12.443634Z</last>

where it should be the opposite (first should be 2021-04-04T15:18:12.443634Z and last should be 2021-05-27T22:41:35.266278Z), and items should reversed.

Thanks!

badlop commented 3 years ago

My commits for #3618 only took care about the Index attribute. I noticed, like you, that the items are returned in reverse order when using <before/>. I thought that was desired because the XEP section is named "Paging Backwards Through a Result Set"...

Now that you mentioned, and I read again the XEP, it is quite clear: the items must be returned always in order:

The last item in the page returned by the responding entity MUST be the item that immediately preceeds the item that the requesting entity indicated it has already received:

https://xmpp.org/extensions/xep-0059.html#backwards

So it's a bug in ejabberd that still requires fixing.