-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Reload Context #3081
base: dev
Are you sure you want to change the base?
Reload Context #3081
Conversation
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. If the flagged items are 🤯 false positivesIf items relate to a ...
|
📝 WalkthroughWalkthroughThe changes in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs (1)
Line range hint
147-161
: Improve disposal pattern and error handlingWhile changing to
ValueTask
is appropriate for disposal, there are some improvements needed:
- Empty catch block silently swallows exceptions
- Disposal pattern could be more robust
Consider this improved implementation:
public virtual async ValueTask DisposeAsync() { try { if (RPC != null) { try { await RPC.InvokeAsync("close"); } catch (RemoteMethodNotFoundException e) { + Log.Exception("Plugin doesn't support close method", e); } + catch (Exception e) when (e is not ObjectDisposedException) + { + Log.Exception("Error during plugin close", e); + } } } finally { - RPC?.Dispose(); - ErrorStream?.Dispose(); + if (RPC != null) + { + RPC.Dispose(); + RPC = null; + } + if (ErrorStream != null) + { + ErrorStream.Dispose(); + ErrorStream = null; + } } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs
(1 hunks)
🔇 Additional comments (1)
Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs (1)
Line range hint 136-161
: Verify impact on other plugins and implementations
The changes to both ReloadDataAsync
and DisposeAsync
methods could affect other plugins and implementations.
Let's verify the impact:
✅ Verification successful
Based on the search results, I can now provide a final response:
Changes to ReloadDataAsync
and DisposeAsync
are safe and properly implemented
The changes to both methods are part of the standard plugin lifecycle and follow the established patterns:
-
ReloadDataAsync
is properly implemented:- Only 2 classes implement
IAsyncReloadable
:JsonRPCPluginV2
andProgram
plugin - The reload functionality is centrally managed through
PluginManager.ReloadDataAsync()
- Error handling for missing remote methods is properly handled
- Only 2 classes implement
-
DisposeAsync
follows correct cleanup pattern:- Proper error handling for remote method calls
- Ensures cleanup of RPC and ErrorStream in finally block
- Used by derived class
ProcessStreamPluginV2
which adds its own cleanup
The changes maintain compatibility with the plugin system's reload and disposal mechanisms as documented in the interfaces.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Find all implementations of IAsyncReloadable
echo "Searching for IAsyncReloadable implementations..."
rg "class.*:.*IAsyncReloadable" -l
# Find all reload method calls
echo "Searching for reload method calls..."
rg "ReloadDataAsync|reload" -A 5
# Find all JsonRPCPluginV2 derived classes
echo "Searching for JsonRPCPluginV2 derived classes..."
rg "class.*:.*JsonRPCPluginV2" -l
Length of output: 97681
public virtual async Task ReloadDataAsync() | ||
{ | ||
SetupJsonRPC(); | ||
return Task.CompletedTask; | ||
try | ||
{ | ||
await RPC.InvokeAsync("reload", context); | ||
} | ||
catch (RemoteMethodNotFoundException e) | ||
{ | ||
} |
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.
Critical: Current implementation may lead to inconsistent plugin state
The current implementation has several issues that need to be addressed:
-
The method combines both restart and reload approaches incorrectly:
- It restarts the RPC connection via
SetupJsonRPC()
- It attempts to call
reload
on the new connection - It doesn't call
initialize
after restart
- It restarts the RPC connection via
-
The
context
variable on line 141 is undefined, which will cause a compilation error. -
Empty catch block silently swallows exceptions, making it difficult to debug issues.
Consider implementing one of these solutions:
public virtual async Task ReloadDataAsync()
{
+ // Solution 1: Restart with initialize
SetupJsonRPC();
+ await RPC.InvokeAsync("initialize", Context);
}
OR
public virtual async Task ReloadDataAsync()
{
- SetupJsonRPC();
try
{
await RPC.InvokeAsync("reload", Context);
}
catch (RemoteMethodNotFoundException e)
{
+ Log.Exception($"Plugin doesn't support reload method", e);
+ // Fallback to restart + initialize
+ SetupJsonRPC();
+ await RPC.InvokeAsync("initialize", Context);
}
}
Committable suggestion skipped: line range outside the PR's diff.
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.
Good work @coderabbitai
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.
@jjw24 Thank you! Let me know if you need any further assistance.
I think this should be consistent with the C# API, so |
Replying to your question in the description. Agree with Yusyuriv. It shouldn't restart plugin. It should do a reload request. I think I only saw one plugin dev using V2, so we can just let the person know. |
🥷 Code experts: no user but you matched threshold 10 See details
Knowledge based on git-blame: To learn more about /:\ gitStream - Visit our Docs |
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
Yeah it's him posted the problem. Sounds good |
There's a problem with the current implementation.
Reload
will restart jsonrpc_v2 plugin, but not callinginitialize
. This may break the plugin state that are not what plugin developer may assume.There are two solution:
initialize
whenever reload.reload
request.This will be a breaking change regardless, but given the relatively small number of v2 plugin now it should be fine.
@Flow-Launcher/team which one would you think is better?