Skip to content

Capture several server thread exceptions#69

Open
kostyanf14 wants to merge 1 commit intomasterfrom
fix-server-log
Open

Capture several server thread exceptions#69
kostyanf14 wants to merge 1 commit intomasterfrom
fix-server-log

Conversation

@kostyanf14
Copy link
Contributor

No description provided.

Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @kostyanf14, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the robustness and maintainability of the server's log fetching component. By refactoring the log retrieval process into a separate method and implementing comprehensive exception handling for common connection-related errors, the server is now more resilient to transient network issues or unexpected WinRM pipeline closures. This change aims to prevent service interruptions and enhance the overall stability of the application.

Highlights

  • Refactoring of Log Fetching Logic: The logic responsible for fetching logs from the WinRM pipeline and writing them to a file has been extracted into a new, dedicated method named start_server_with_log_fetcher. This improves code organization and readability within the load_toolshck_server method.
  • Enhanced Server Thread Exception Handling: Robust error handling has been implemented within the log_fetcher thread. It now explicitly catches and gracefully handles WinRM::WinRMError, Errno::ECONNRESET, Errno::ECONNREFUSED, and Errno::EPIPE exceptions. This prevents the server from crashing if the WinRM connection or pipeline is unexpectedly closed during log retrieval, ensuring greater stability.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lib/server.rb
    • Introduced a new private method start_server_with_log_fetcher to encapsulate the log fetching and writing process.
    • Modified the load_toolshck_server method to utilize the new start_server_with_log_fetcher method within its Thread.new block.
    • Added exception handling for WinRM::WinRMError, Errno::ECONNRESET, Errno::ECONNREFUSED, and Errno::EPIPE within the log_fetcher thread to prevent crashes.
    • Included a logger call to record messages when these specific exceptions are caught, indicating a non-critical issue.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the robustness of the server by handling exceptions in the log fetcher thread, which prevents potential crashes. The extraction of the start_server_with_log_fetcher method is a good step for clarity. I've provided a couple of suggestions to further improve the code by enhancing encapsulation and making the error logging more informative for debugging purposes.

logger('debug', 'server/initialize') { 'deployed' }
end

def start_server_with_log_fetcher

Choose a reason for hiding this comment

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

medium

This method appears to be a helper for load_toolshck_server and is not used outside of this class. It's good practice to make such methods private to improve encapsulation. You can use private def to make this specific method private.

  private def start_server_with_log_fetcher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it already in the private part

# still fetching messages, so we need to catch both.
# In any case, Ether will restart the server before the next command execution,
# so we won't be left with a hanging thread
logger('error', 'server/log_fetcher') { "failed to fetch log message: #{e.message}" }

Choose a reason for hiding this comment

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

medium

For better debugging, it would be helpful to include the exception class in the log message. This is also consistent with how exceptions are logged elsewhere in the codebase, for example in the log_exception method in ether.rb.

      logger('error', 'server/log_fetcher') { "failed to fetch log message: [#{e.class}] #{e.message}" }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to debug this actually, just don't crash the full application.
@YanVugenfirer Maybe report as a warning instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree

Copy link

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.

Pull request overview

This PR updates the WinRM server log-fetcher thread to better handle common connection/pipeline shutdown exceptions without taking down the server flow.

Changes:

  • Extracted the log fetcher pipeline/file-writing logic into start_server_with_log_fetcher.
  • Added a targeted rescue in the log-fetcher thread for several WinRM/socket-related exceptions and logs the failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# Safe to ignore as the most likely cause is that the pipeline was closed
# before we finished fetching all messages and we don't want to crash the server
# in that case. This can happen when the server is stopped while we're still fetching messages.
# WinRMError be raised instead of Errno::EPIPE when the WinRM connection is closed while we're
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Grammar in this comment is off: "WinRMError be raised" should be updated (e.g., "WinRMError can be raised") for clarity.

Suggested change
# WinRMError be raised instead of Errno::EPIPE when the WinRM connection is closed while we're
# WinRMError can be raised instead of Errno::EPIPE when the WinRM connection is closed while we're

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +89
# so we won't be left with a hanging thread
logger('error', 'server/log_fetcher') { "failed to fetch log message: #{e.message}" }
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This rescue path is described as "safe to ignore", but it currently logs at error level. That can create noisy/false-positive error logs during normal shutdown/restart. Consider lowering this to warn/debug, and/or including e.class and only using error for truly unexpected failures.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants