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

Data races in sample after parallel store update calls #880

Open
zerobias opened this issue Mar 28, 2023 · 1 comment
Open

Data races in sample after parallel store update calls #880

zerobias opened this issue Mar 28, 2023 · 1 comment
Labels
bug Something isn't working core effector package
Milestone

Comments

@zerobias
Copy link
Member

What is the current behavior:

In a complex edge case with two attach with arrays in source old store value is leaking. Curiously, this could be fixed when one of targets is effect, not event

export const initApp = createEvent<number>();
export const reInitApp = createEvent<number>();
export const startRequest = createEvent();
export const resetApp = createEvent();

export const $ownerId = createStore<number>(-1);

const requestFx = createEffect((value) => {
  console.log("ownerId in calling requestFx: ", value, $ownerId.getState());
});

$ownerId.reset(resetApp)

export const fetchFx = createEffect(() => ({}));

export const fetchMoreAFx = attach({effect: fetchFx, source: [$ownerId]});
export const fetchMoreBFx = attach({effect: fetchFx, source: [$ownerId]});

sample({
  clock: startRequest,
  source: [$ownerId], // <--- incorrect value
  fn: ([ownerId]) => {
    console.log(ownerId, $ownerId.getState())
    return ownerId
  },
  target: requestFx
});

sample({
  clock: reInitApp,
  source: $ownerId,
  filter: (ownerId, newOwnerId) => ownerId !== newOwnerId,
  fn: (_, payload) => payload,
  target: [resetApp, initApp]
});

$ownerId.on(initApp, (_, ownerId) => ownerId);

initApp(1);
reInitApp(3);
startRequest();

Bug

No bug

@zerobias zerobias added bug Something isn't working needs triage core effector package and removed needs triage labels Mar 28, 2023
@zerobias zerobias added this to the effector 24 milestone May 29, 2024
@zerobias
Copy link
Member Author

Looks like fixing it may be a breaking change so scheduled it for effector 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core effector package
Projects
None yet
Development

No branches or pull requests

1 participant