emailjs / emailjs-imap-client

Low-level JS IMAP client for all your IMAP needs.
MIT License
557 stars 123 forks source link

Fixed a concurrency issue where a selectMailbox precheck would not fire. #127

Closed gudmundurg74 closed 7 years ago

gudmundurg74 commented 7 years ago

The _selectedMailbox check in the precheck functions does not take into account any potential SELECT commands on the queue or currently running, it only checks what is currently selected. So this here also checks the queue and anything currently running, looking for the last SELECT to run before the precheck's command should run.

See the integration test for a reproduction of the problem: box A is originally selected. Then a request to select B is sent, while that request is under way a setFlags in A is requested. A is still selected so the selectMailbox precheck does not fire. B gets selected and setFlags is then run there instead of A.

nifgraup commented 7 years ago

I made a workaround in #93 for this which turned out to be incomplete. Should that be removed? Or perhaps keep it until the queueing mechanism gets the ability to reorder commands to minimize unnecessary SELECTs.

gudmundurg74 commented 7 years ago

That looks like a feature to group commands of a single mailbox behind a selectMailbox, I think we should just keep it, like you say, until we optimize the queue.