-
Notifications
You must be signed in to change notification settings - Fork 0
fix(extractor): resolve-aware ignored-Subscribe — only flag when Subscribe returns IDisposable (mined StackExchange.Redis) #93
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System; | ||
|
|
||
| namespace Own.Samples; | ||
|
|
||
| // P-004 resolve-aware ignored-Subscribe (WPF004), mined: StackExchange.Redis ConnectionMultiplexer.Sentinel. | ||
| // A bare `x.Subscribe(...)` is a leak ONLY when the call returns an IDisposable token (the Rx | ||
| // `IObservable<T>.Subscribe()` shape). StackExchange.Redis's `ISubscriber.Subscribe(channel, handler, | ||
| // flags)` returns VOID — there is no token to leak — so it must NOT be flagged. The IDisposable-returning | ||
| // case stays flagged (DisposableSubscriber below, and MessengerViewModel.InboxViewModel). | ||
|
|
||
| // a void-returning Subscribe (the handler overload) -> no IDisposable token -> must be SILENT. | ||
| public sealed class VoidSubscriber | ||
| { | ||
| public VoidSubscriber(IRedisSubscriber sub) | ||
| { | ||
| sub.Subscribe("+switch-master", (_, _) => { }); // returns void -> nothing to dispose -> SILENT | ||
| } | ||
| } | ||
|
|
||
| // control: a Subscribe that DOES return an IDisposable token, ignored -> STILL a leak -> WARN. | ||
| public sealed class DisposableSubscriber | ||
| { | ||
| public DisposableSubscriber(IObservableBus bus) | ||
| { | ||
| bus.Subscribe(_ => { }); // returns IDisposable, ignored -> WARN (resolve-aware still fires) | ||
Check warningCode scanning / Own.NET owned resource not released on all paths (possible leak) Warning
the result of 'bus.Subscribe' is ignored — the IDisposable subscription is never disposed, leaking 'DisposableSubscriber' (leak) [resource: subscription token]
|
||
|
|
||
| } | ||
| } | ||
|
|
||
| // Codex control: a `dynamic` receiver gives Subscribe a dynamic return type — we cannot prove it is | ||
| // void / non-IDisposable, so it keeps the benefit of the doubt and STILL warns. | ||
| public sealed class DynamicSubscriber | ||
| { | ||
| public DynamicSubscriber(dynamic bus) | ||
| { | ||
| Action<object> handler = _ => { }; | ||
| bus.Subscribe(handler); // dynamic return -> unknown -> WARN | ||
Check warningCode scanning / Own.NET owned resource not released on all paths (possible leak) Warning
the result of 'bus.Subscribe' is ignored — the IDisposable subscription is never disposed, leaking 'DynamicSubscriber' (leak) [resource: subscription token]
|
||
|
|
||
| } | ||
| } | ||
|
|
||
| // StackExchange.Redis-style: the handler overload returns void. | ||
| public interface IRedisSubscriber | ||
| { | ||
| void Subscribe(string channel, Action<string, string> handler); | ||
| } | ||
|
|
||
| // Rx-style: Subscribe hands back an IDisposable unsubscribe token. | ||
| public interface IObservableBus | ||
| { | ||
| IDisposable Subscribe(Action<object> handler); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.