Skip to content

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Apr 9, 2025

Fix JsonRpc plugin connection loss exception

  • Ignore ConnectionLostException when JsonRPC v2 plugins execute close & reload_context method.
  • Add exception handler when calling close & reload_context method.

Fix #3173, #3299.

@prlabeler prlabeler bot added the bug Something isn't working label Apr 9, 2025
@Jack251970 Jack251970 requested a review from Copilot April 9, 2025 10:12
Copy link

gitstream-cm bot commented Apr 9, 2025

🚨 Warning: Approaching Monthly Automation Limit

Monthly PRs automated: 226/250

Your organization has used over 90% of its monthly quota for gitStream automations. Once the quota is reached, new pull requests for this month will not trigger gitStream automations and will be marked as “Skipped”.

To avoid interruptions, consider optimizing your automation usage or upgrading your plan by contacting LinearB.

@Jack251970 Jack251970 added this to the 1.20.0 milestone Apr 9, 2025
@Jack251970 Jack251970 linked an issue Apr 9, 2025 that may be closed by this pull request
2 tasks
@Jack251970 Jack251970 changed the title Fix Jsonrpc connection loss exception Fix JsonRpc plugin connection loss exception Apr 9, 2025
Copy link

gitstream-cm bot commented Apr 9, 2025

🥷 Code experts: no user but you matched threshold 10

Jack251970 has most 👩‍💻 activity in the files.

See details

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB 1 additions & 13 deletions
JAN
DEC
NOV

Knowledge based on git-blame:

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs

Activity based on git-commit:

Jack251970
APR
MAR 6 additions & 1 deletions
FEB 13 additions & 29 deletions
JAN
DEC
NOV

Knowledge based on git-blame:

Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:

To learn more about /:\ gitStream - Visit our Docs

This comment has been minimized.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs:22

  • [nitpick] Using 'new' to hide the inherited JsonRPC constant can be confusing. Consider adding documentation or revisiting the design to clarify the necessity of shadowing the base constant.
public new const string JsonRPC = "JsonRPC";

Copy link

gitstream-cm bot commented Apr 9, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

@Jack251970 Jack251970 requested a review from cibere April 9, 2025 10:13
@Jack251970
Copy link
Member Author

Jack251970 commented Apr 9, 2025

@cibere Could you please check if this PR can fix your plugin's issue? And also please check if your plugin is closed after FL exiting (Here I just ignore that exception and I am not sure if the plugin with this issue can be closed entirely). Thanks!

@Jack251970 Jack251970 enabled auto-merge April 9, 2025 10:14
Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

📝 Walkthrough

Walkthrough

This pull request updates three plugin files. In the main plugin file, the code now reorders using directives, redefines the JSON-RPC constant using the new modifier, and removes several settings fields and properties. In the base plugin file, the using directives are similarly reorganized. In the V2 plugin, exception handling is enhanced by simplifying one catch block, adding a specific catch for connection loss, and including a general exception catch that logs errors.

Changes

Files Change Summary
Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs, Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs Reordered using directives (removal then re-addition of Flow.Launcher.Core.Resource;) for better organization.
Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs Updated constant declaration to use new; removed the SettingConfigurationPath, SettingPath properties, the settingSerializeOption static field, and the _settingControls dictionary to simplify settings management.
Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs Modified exception handling in ReloadDataAsync and DisposeAsync methods: simplified catch for RemoteMethodNotFoundException, added a catch for ConnectionLostException, and introduced a general exception catch that logs errors.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant PluginV2 as JsonRPCPluginV2
    participant Logger as Context.API.LogException

    Caller->>PluginV2: Invoke ReloadDataAsync / DisposeAsync
    alt RemoteMethodNotFoundException thrown
        PluginV2->>PluginV2: Handle silently (simplified catch)
    else ConnectionLostException thrown
        PluginV2->>PluginV2: Handle connection lost exception
    else General Exception thrown
        PluginV2->>Logger: Log exception with plugin name
    end
    PluginV2->>Caller: Return response
Loading

Assessment against linked issues

Objective Addressed Explanation
[#3173] BUG: The JSON-RPC connection with the remote party was lost

Suggested reviewers

  • Garulf
  • Yusyuriv
  • jjw24

Poem

I'm a little rabbit, hopping with delight,
Coding in flows from morning to night.
The settings trimmed, exceptions caught with care,
Bugs are chased away into the software air.
With a twitch of my nose and a joyful little cheer,
I celebrate these changes—happy code is here!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4095eb4 and 5a2db37.

📒 Files selected for processing (1)
  • Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs (1)

171-225: 💡 Verification agent

🧩 Analysis chain

Verify the ExecuteAsync method's exception handling for connection loss.

Based on the PR objectives, this change aims to fix JSON-RPC connection loss exceptions, but I don't see explicit handling for connection-related exceptions in this method. Consider adding specific handling for network-related exceptions (like IOException or WebException).

Also, the method creates a registeredEvent to handle cancellation but doesn't have specific handling for connection loss during the process.WaitForExitAsync or the Task.WhenAll operations.

Run the following script to search for any changes to exception handling related to connection loss in other files:


🏁 Script executed:

#!/bin/bash
# Search for JsonRPC v2 plugin files and relevant exception handling

echo "Searching for JsonRPCPlugin v2 implementation files..."
fd -e cs "JsonRPC.*V2" --type f

echo "Searching for connection loss exception handling..."
rg -A 3 -B 3 "catch\s*\(\s*(IOException|WebException|SocketException|ConnectionException)"

echo "Searching for changes in Dispose methods in JsonRPC plugins..."
rg -A 5 -B 2 "Dispose\s*\(\s*\)|IDisposable" $(fd -e cs "JsonRPC")

Length of output: 2249


Action: Enhance Connection Loss Exception Handling in ExecuteAsync

After verifying the code and the search results:

  • The current implementation in Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs (lines 171–225) only catches an OperationCanceledException during the asynchronous operations.
  • Our search did not reveal any explicit handling for network-related exceptions (e.g., IOException, WebException, SocketException, or ConnectionException) within this method.
  • Although cancellation is managed via the registeredEvent, exceptions related to connection loss during process.WaitForExitAsync(token) or Task.WhenAll(sourceCopyTask, errorCopyTask) are not specifically handled.

Recommendations:

  • Add explicit catch blocks for network-related exceptions (such as IOException or WebException) around the asynchronous process handling to ensure that connection loss is detected and managed appropriately.
  • Review error logging to differentiate between cancellation and genuine connection errors, ensuring the error messages are informative.
  • Consider consistency with JsonRPCPluginV2 (as observed in the lookup) if similar exception handling is expected across implementations.
🧹 Nitpick comments (1)
Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs (1)

22-22: Consider adding a comment explaining the use of the new modifier.

The addition of the new modifier to the JsonRPC constant explicitly indicates that this constant is intended to hide the identically named constant from the base class JsonRPCPluginBase. While this is syntactically correct, adding a comment would improve code clarity for future maintainers.

-        public new const string JsonRPC = "JsonRPC";
+        // Explicitly hiding the base class constant to avoid ambiguity
+        public new const string JsonRPC = "JsonRPC";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e740b1 and 8730a5f.

📒 Files selected for processing (3)
  • Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs (2 hunks)
  • Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (1 hunks)
  • Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs (1)
Learnt from: jjw24
PR: Flow-Launcher/Flow.Launcher#3081
File: Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs:136-145
Timestamp: 2025-04-03T10:38:00.009Z
Learning: In Flow.Launcher JsonRPCV2 plugins, the `reload_data` method is optional for plugins to implement. When the method is not found (RemoteMethodNotFoundException), it should be silently caught without logging as this is an expected scenario.
🧬 Code Graph Analysis (1)
Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (1)
Flow.Launcher/Msg.xaml.cs (1)
  • System (44-47)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (4)
Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs (2)

117-126: Good enhancement of the exception handling in ReloadDataAsync.

The changes to the exception handling are well structured:

  1. The simplified catch for RemoteMethodNotFoundException follows the proper pattern as this exception is expected when plugins don't implement the optional reload_data method.
  2. Adding specific handling for ConnectionLostException directly addresses the PR objective of fixing connection loss exceptions.
  3. The general exception handler with proper logging will help diagnose other unexpected issues without crashing the application.

135-144: Good implementation of consistent exception handling in DisposeAsync.

These changes mirror the improvements made to the ReloadDataAsync method:

  1. Silently handling RemoteMethodNotFoundException for plugins that don't implement the close method
  2. Adding specific handling for ConnectionLostException which prevents unhandled exceptions during plugin disposal
  3. Adding appropriate error logging for unexpected exceptions

This consistent approach to exception handling across similar methods improves the robustness of the plugin system.

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (1)

1-8: Using directive reorganization looks good.

The reordering of the using directive for Flow.Launcher.Core.Resource is a non-functional change that maintains code organization consistency. This matches similar changes in other files like JsonRPCPlugin.cs.

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs (1)

1-9: Using directive reorganization looks good.

The reordering of the using directive for Flow.Launcher.Core.Resource is a non-functional change that maintains code organization consistency. This matches similar changes in the JsonRPCPluginBase.cs file.

@Jack251970 Jack251970 requested a review from Copilot April 9, 2025 11:27

This comment has been minimized.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs:21

  • Hiding the base class constant using the 'new' modifier can be confusing; consider removing the 'new' modifier or renaming this constant to avoid potential shadowing issues.
public new const string JsonRPC = "JsonRPC";

@Jack251970 Jack251970 requested a review from Copilot April 9, 2025 11:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs:123

  • [nitpick] Although intentionally ignored, consider logging the ConnectionLostException at a debug level to aid troubleshooting if future issues arise.
catch (ConnectionLostException)

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs:21

  • [nitpick] Using the 'new' modifier to hide the inherited constant may cause confusion. If overriding is not explicitly required, consider removing 'new' or renaming the constant for clarity.
public new const string JsonRPC = "JsonRPC";

This comment has been minimized.

Copy link

github-actions bot commented Apr 9, 2025

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@cibere
Copy link
Contributor

cibere commented Apr 9, 2025

@cibere Could you please check if this PR can fix your plugin's issue?

It seems to do so.

And also please check if your plugin is closed after FL exiting (Here I just ignore that exception and I am not sure if the plugin with this issue can be closed entirely). Thanks!

The problem stems from the plugin closing itself voluntarily, so afaik, there is nothing for flow to cleanup

@Jack251970 Jack251970 merged commit b362bc6 into dev Apr 9, 2025
10 checks passed
@Jack251970 Jack251970 deleted the jsonrpc_connection_loss branch April 9, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Code Quality

Projects

None yet

3 participants