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

Fix/mutable state bug #11

Closed
wants to merge 2 commits into from

Conversation

blak3mill3r
Copy link

First, thank you for this library! I'm finding it useful.

There is a (very) subtle shared-state bug with the mutable cache fields which I fixed here

I don't have time to do this properly right now, though I would be happy to do so at some point... I didn't update the tests or even make sure that my changes were entirely necessary, but they do fix a nasty and subtle flaw which we ran into today using this library.

mutable fields on `RWFocus` and `ROFocus` are shared between the
implementations of the `IDeref` and `IRef` interfaces

each interface tested in isolation is correct

the combination of the two is subtly incorrect in at least the
following sequence:

1) a watch is added to a derived atom
2) the derived atom is dereferenced
   * this `set!`s the value `.-srccache`
3) the source atom changes, firing the `main-watcher`
   * it sees the value of `.-srccache` from the `deref`...
   * therefore it does not run the watchers on the derived atom, since
     this test is true:
       `(identical? newv (.-srccache self))`

this commit fixes the issue by splitting 3 independent mutable fields
for `srccache`, `oldcache`, and `cache`

I did not test if it is necessary to split all 3...

this change is sufficient to fix the bug, but it may also be overkill,
I am only certain that there is a problem with sharing `srccache`, not
the other two
@niwinz
Copy link
Member

niwinz commented Jun 6, 2018

First of all, thanks for your time.

About the issue, after looking many times the code i don't see any relevant difference with the previous code:

  • zcache is replaces cache but is used in the identical manner.
  • zoldcache is added, assigned to previous cache but not used.
  • cache seems that becomes unused.
  • only the deref impl is changed, other functions are untouched.

Can you explain please which bug is fixing this, because i don't understad that is intend to solve. Maybe you first need write a test case that reproduces the bug?

@blak3mill3r
Copy link
Author

Yes, I'll be glad to put together a test case that shows the problem, but I will not be able to get to it right away.

@epeters-jrmngndr
Copy link

@blak3mill3r I think you forgot about this

@aiba
Copy link
Collaborator

aiba commented Sep 3, 2024

Closing this issue until someone can provide a reproducible test case or a coherent explanation of the problem.

@aiba aiba closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants