PolymerLabs/actor-helpers

Issues in the message store

villevaljus opened this issue · 0 comments

I'm reporting two partly related issues. I didn't have permission to push a branch and create a pull request, so I'm attaching Git patch files containing my suggested fix. The commits are built on top of each other, so they should be merged in order.

1. initializeQueues() doesn't remove messages before the current cursor

Calling initializeQueues() would remove messages only from the beginning of the current cursor value. It should remove all messages instead, so the cursor need to be reset before calling the popMessages().

2. Popping messages for a recipient might move the cursor past other recipients’ messages

When sending two messages (”message 1” and “message 2”) to two different recipients immediately one after another, it’s possible that a rare race condition happens. During the race condition, both messages 1 and 2 are stored in the IndexedDB before an event informing the corresponding recipient about message 1 is received and the recipient begins reading the message using the popMessages() function. When that message 1 is being read, it will also move the lastCursorId past message 2, because message 2 has already been stored in the database. When an event informing about message 2 reaches the corresponding recipient, and the recipient starts to read that message via popMessages(), it can’t read the message, because the cursor points beyond the message.

0001-Fix-initializeQueues-to-remove-all-existing-messages.patch
0002-Use-individual-cursors-for-each-recipient.patch