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

Reload Context #3081

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@ private void SetupJsonRPC()
RPC.StartListening();
}

public virtual Task ReloadDataAsync()
public virtual async Task ReloadDataAsync()
{
SetupJsonRPC();
return Task.CompletedTask;
try
{
await RPC.InvokeAsync("reload", Context);
}
catch (RemoteMethodNotFoundException e)
{
}
Comment on lines +136 to +145
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Critical: Implementation needs to be fixed for process-based plugins

The verification revealed that ProcessStreamPluginV2 is the only direct inheritor of JsonRPCPluginV2, and it already implements proper process management. The current implementation in JsonRPCPluginV2.ReloadDataAsync() causes redundant RPC setup when called from ProcessStreamPluginV2, which could lead to race conditions.

The suggested fix remains valid and is backward compatible:

 public virtual async Task ReloadDataAsync()
 {
-    SetupJsonRPC();
     try
     {
         await RPC.InvokeAsync("reload", Context);
     }
     catch (RemoteMethodNotFoundException e)
     {
+        Log.Exception("Plugin doesn't support reload method", e);
+        throw;
     }
 }
🔗 Analysis chain

Critical: Implementation may lead to inconsistent plugin state

The current implementation has several issues:

  1. It incorrectly combines both restart and reload approaches by calling SetupJsonRPC() followed by a reload request
  2. It doesn't call initialize after restart, which may lead to an inconsistent plugin state
  3. Empty catch block silently swallows exceptions, making debugging difficult

Based on the PR objectives and discussion consensus, implement the reload-only approach:

 public virtual async Task ReloadDataAsync()
 {
-    SetupJsonRPC();
     try
     {
         await RPC.InvokeAsync("reload", Context);
     }
     catch (RemoteMethodNotFoundException e)
     {
+        Log.Exception("Plugin doesn't support reload method", e);
+        throw; // Propagate the error to inform plugin developers
     }
 }

Let's verify if any plugins are using the old behavior:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for V2 plugins that might rely on plugin restart during reload
ast-grep --pattern 'class $_ : JsonRPCPluginV2'

Length of output: 49


Script:

#!/bin/bash
# Search for class inheritance and usages with context
rg -U "class.*:.*JsonRPCPluginV2" -A 5
rg "JsonRPCPluginV2" "*[Tt]est*.cs" -A 5
rg "ReloadDataAsync" -A 5

Length of output: 4742

}

public virtual async ValueTask DisposeAsync()
Expand Down
Loading