-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Ensure Disposable.NULL
always returns a new Disposable
#11053
Ensure Disposable.NULL
always returns a new Disposable
#11053
Conversation
Is this related to the fact that |
I honestly dislike what's being done to disposable references in Anyway, I would propose two alternative changes:
Those alternatives both have the benefit of requiring no changes for downstream projects. WDYT? |
Yes, exactly.
Yeah, it's certainly not ideal. I'm not exactly sure what system to put in its place: if the point of disposables is to avoid leaks, then having some mechanism for removing references to them that occur outside of the collection currently disposing of itself is probably correct - otherwise they're leaking - but it probably doesn't make sense to have two different collections that can both dispose of something the holder of the other collection might be depending on. So it would probably make sense to guarantee that no disposable is ever put in two disposable collections, but I'm not sure how frequently that's happening in the wild or how much fixing it would take to ensure it doesn't happen.
I'm in favor of 1, though in general I'm not very fond of manual prototype manipulation. But as you say, it would avoid having adopters need to do anything. |
I don't see how to enforce that nicely, I have better hope with being careful with our references and not sharing them to multiple dependants that all will try to dispose the same instance. To me it sounds like a "double free" kind of issue. Where is Rust's borrow checker when we need it? :) Let's go with my first proposed change, I don't like it either but you can add a comment mentioning how each access will return a new disposable instance (the jsdoc should go in the declared namespace?). |
Disposable.NULL
and replace with Disposable.createNull
Disposable.NULL
always returns a new Disposable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What it does
Because of the way
DisposableCollections
handle disposal of their members, it is unsafe to addDisposable.NULL
to any disposable collection: doing so risks disposal of one collection marking another collection as disposed inappropriately. This PR adds a test showing the risk ofDisposable.NULL
and replacesDisposable.NULL
throughout the framework with a new methodDisposable.createNull
, with a test to demonstrate that disposables created in that way are safe for use inDisposableCollections
.How to test
disposable.spec.ts
pass (and look correct)disposable.ts
anddispospable.spec.ts
just replaceDisposable.NULL
withDisposable.createNull
Disposable.NULL
remain in the framework.Review checklist
Reminder for reviewers