Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trivial] Lwt_sequence.fold_r may visit items twice or more during concurrent removal #405

Closed
stijn-devriendt opened this issue Jun 14, 2017 · 2 comments

Comments

@stijn-devriendt
Copy link
Contributor

Looking at https://github.com/ocsigen/lwt/blob/master/src/core/lwt_sequence.ml#L206
the fold_r skips to the next node instead of the previous one when node_active is false.

This might cause a node to be visited twice or more.

@aantron
Copy link
Collaborator

aantron commented Jun 14, 2017

Fixing this particular issue in isolation should be as easy as changing the line to say node_prev instead of node_next.

I've created a separate issue (#406) for writing an actual test suite for Lwt_sequence.

Actually triggering this bug is a bit involved. I believe you have to first delete the current node inside f, and then also delete its next and/or previous node.

This is because... (picture):

...  <->  C  <->  N  <->  ...

C is the current node at some point during traversal, and N is a next (resp., previous) node, and we want to reach N from C with N not "active."

  • When a node N becomes not active, the previous and next nodes are updated not to point to it. This code is thread-safe in current OCaml due to the global lock, and it does not interact with Lwt concurrency either. So, under ordinary circumstances, removing N would make it impossible to go from C to N.
  • So, the only way to reach a not active node N during traversal, is for C's node_next/node_prev to not have been updated by the removal code linked above.
  • In order for those links not to be updated, C must become not the next/previous node of N. For that, C must first get removed, which will unlink it from the point of view of N, but will not update the links in C: C will still point to N. When N is then also removed, the removal doesn't update the links in C, so C still points to the now-inactive node N. The traversal will then happily reach an inactive node.

@aantron aantron changed the title Lwt_sequence.fold_r may visit items twice or more during concurrent removal [trivial] Lwt_sequence.fold_r may visit items twice or more during concurrent removal Jun 14, 2017
stijn-devriendt added a commit to westerndigitalcorporation/lwt that referenced this issue Jul 4, 2017
@aantron
Copy link
Collaborator

aantron commented Jul 4, 2017

Was fixed by the linked commit, in PR #434.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants