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

Exceptions in watched callback leave Watcher in inconsistent state #209

Open
prophile opened this issue Apr 29, 2024 · 1 comment
Open

Comments

@prophile
Copy link
Contributor

prophile commented Apr 29, 2024

Consider the following code:

const a = new Signal.State(0)
const b = new Signal.State(1, {
  [Signal.subtle.watched]: () => {
    throw new Error("this failed");
  },
})
const c = new Signal.State(2)

const watcher = new Signal.subtle.Watcher(() => {
  console.log("notified")
});
try {
  watcher.watch(a, b, c);
} catch (e) {
  console.log(e.message)
}

console.log("a sinks", Signal.subtle.introspectSinks(a))
console.log("b sinks", Signal.subtle.introspectSinks(b))
console.log("c sinks", Signal.subtle.introspectSinks(c))
console.log("watcher sources", Signal.subtle.introspectSources(watcher))

In the polyfill at f7c550b, and according to the algorithm in "Method: Signal.subtle.Watcher.prototype.watch(...signals)", this error thrown in the watched callback leaves Watcher in an inconsistent state. a has the watcher as a sink but neither b nor c do (so we have a case where watcher.watch has added some, but not all, of its arguments as sources); also, the watcher lists both a and b as sources so its state is inconsistent as to whether b is watched or not.

@littledan
Copy link
Member

Not fixed by #223 . What should we do about multiple exceptions? Should we unwind everything?

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

No branches or pull requests

2 participants