collab_client: Fix race condition with character composition#4983
collab_client: Fix race condition with character composition#4983
Conversation
ingoncalves
left a comment
There was a problem hiding this comment.
Thanks a lot for this fix proposal!
I checked out this branch and ran the test that covers this bug and everything looks fine.
My first suggestion is to add the helper src/tests/frontend/helper/multipleUsers.js and the test src/tests/frontend/specs/collab_client.js from #4979 to this PR in order to cover this fix and ensure that it will not break again in the future.
My second suggestion is in relation to serverMessageTaskQueue. As I am not used to this code and as it has a complex logic, it was a little complicated to understand what this code does. So, I commented on some suggestions that can help other people to understand it better.
My last suggestion is not specifically about this PR. We could be able to have unit tests in the front-end as well. Today, we only have integrations tests, and some components, such as collab_client.js, contain a complex logic that could be better stressed within unit tests. It would also allow simulating complex scenarios, such as network problems. If you agree, we could manage to set up the tools necessary to have unit tests in the front-end in the future.
Will do.
I would love to have better unit tests. Unfortunately, tests take time to write, and unless people encounter more bugs with this code I think that adding more tests is low priority. I will happily accept PRs that add tests, but I don't have the time to write them myself. |
Great!!! So we will manage to add some unit tests soon. At least, it will be a starting point! |
d35eeee to
fa0018a
Compare
|
I pushed some revisions and tests. @ingoncalves: Would you review the commits starting with "tests: Add regression tests for character composition race"? If they look OK to you I'll squash the "for squash" commits into the "tests: Add regression tests for character composition race" commit (so you'll be the one with the credit/blame) unless you want those changes to be separate. |
Also rename the `t` variable to `now` to improve readability.
b74dda9 to
0276f92
Compare
|
With the old behavior the only place where msgQueue is filled for the first(!) time is during processing of a I don't think it matters, as long as order of message processing is retained. |
Nice work! LGTM! |
Yes, nice catch.
It might matter for timeouts (if the user is taking a long time to compose). I'll change it to match the previous behavior. |
Move server message queue processing out of `handleUserChanges()` for
the following reasons:
* Fix a race condition: Before this change the client would stop
processing incoming messages and stop sending changes to the
server if a `NEW_CHANGES` message arrived while the user was
composing a character and waiting for an `ACCEPT_COMMIT` message.
* Improve readability: The `handleUserChanges()` function is for
handling changes from the local user, not for handling changes
from other users.
* Simplify the code.
0276f92 to
0a64bc8
Compare
Done. We might also want to defer |
Multiple commits:
ACCEPT_COMMITcodecaughtErrorsstatevar tocommittingboolDate.now()instead of casting a Date objectNO_COMMIT_PENDINGhandlingThis should fix #4978. Also see PR #4979, which is a different approach to fix the same problem.
@ingoncalves What are your thoughts about this approach?