scrolling: Fix out-of-order bug in the message list.

The issue has a lot of extra details, but in short, if several
messages were sent at very close to the same time, it's possible that
the event queues will receive the "new message" events out-of-order.
This, in turn, could cause `get_events` to return an incorrectly
sorted block of messages.  These would then be passed into
`message_list.add_messages`, which doesn't handle that sort of
unsorted situation correctly (in short, the `self.first.id()`
comparison checks are not accurate for that situation, since we don't
update the boundaries after the first messages is processed).

The end result of this bug was that it was possible for the message
list to be out-of-order, which in turn would cause exceptions when
scrolling with the mouse.

Fixes #6948.
This commit is contained in:
Tim Abbott
2017-10-11 15:49:25 -07:00
parent 9378489367
commit c1f12e3f8a
2 changed files with 9 additions and 1 deletions

View File

@@ -89,6 +89,10 @@ function get_events_success(events) {
});
if (messages.length !== 0) {
// Sort by ID, so that if we get multiple messages back from
// the server out-of-order, we'll still end up with our
// message lists in order.
messages = _.sortBy(messages, 'id');
try {
messages = echo.process_from_server(messages);
message_events.insert_new_messages(messages);