Skip to content

docs: add design doc for etcd watch and session lifecycle fixes#6

Open
xiaofan-luan wants to merge 1 commit intomainfrom
etcd-watch-session-lifecycle-fix
Open

docs: add design doc for etcd watch and session lifecycle fixes#6
xiaofan-luan wants to merge 1 commit intomainfrom
etcd-watch-session-lifecycle-fix

Conversation

@xiaofan-luan
Copy link
Contributor

Summary

This PR adds a design document describing fixes for several reliability issues in session_util.go:

  • Handle error return from checkIDExist() and panic on failure
  • Add context cancellation check in getServerIDWithKey() loop
  • Add keepalive timeout protection to exit when no response within TTL
  • Use watcher's own context for etcd Watch calls instead of session context
  • Handle nil PrevKv on DELETE events gracefully
  • Fix ProcessActiveStandBy to handle ErrCompacted by rewatching with latest revision

Related

🤖 Generated with Claude Code

This document describes fixes for several reliability issues in session_util.go:
- Handle error return from checkIDExist() and panic on failure
- Add context cancellation check in getServerIDWithKey() loop
- Add keepalive timeout protection
- Use watcher's own context for etcd Watch calls
- Handle nil PrevKv on DELETE events
- Fix ProcessActiveStandBy to handle ErrCompacted by rewatching

Related to: milvus-io/milvus#7989

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sre-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xiaofan-luan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link

Summary of Changes

Hello @xiaofan-luan, 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 introduces a comprehensive design document detailing critical reliability improvements for the etcd session utility module. The document outlines solutions to address various edge cases, including silent failures, infinite loops, zombie sessions, resource leaks, and watch failures, ensuring a more robust and stable distributed system by proactively handling common etcd-related issues.

Highlights

  • Error Handling: Improved error handling in checkIDExist() to prevent silent failures and ensure early panic on etcd transaction errors, promoting fail-fast behavior.
  • Context Cancellation: Added explicit context cancellation checks within the getServerIDWithKey() loop to ensure prompt exit and prevent infinite loops when the operation's context is cancelled.
  • Keepalive Timeout Protection: Implemented a keepalive timeout mechanism based on the session's TTL. If no keepalive response is received within this period, the session is considered expired, and the process exits to prevent 'zombie sessions'.
  • Watcher Context Management: Refactored etcd watch calls to use dedicated, cancellable contexts for each watcher, derived from the main session context. This ensures proper resource cleanup and cancellation when watcher.Stop() is called.
  • Nil PrevKv Handling: Added graceful handling for DELETE events where ev.PrevKv might be nil, preventing potential panics and logging a warning instead of crashing.
  • ErrCompacted Recovery: Enhanced ProcessActiveStandBy to recover from ErrCompacted errors by fetching the latest etcd revision and restarting the watch operation, ensuring continuous monitoring despite compaction events.

🧠 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.

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 is a well-written and comprehensive design document. It clearly outlines the reliability issues found in session_util.go and details the fixes for each one. The motivation is clear, the design details are well-explained with illustrative code snippets, and the test plan is thorough. The document effectively communicates the scope and impact of the changes. I have one minor suggestion to improve the clarity of a code snippet.

```go
keepaliveTimeout := time.Duration(s.sessionTTL) * time.Second
timer := time.NewTimer(keepaliveTimeout)
for {

Choose a reason for hiding this comment

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

medium

The code snippet uses break keepaliveLoop on line 78, but the for loop on line 74 is not labeled. For improved clarity and to make the code snippet self-contained and correct, consider adding the keepaliveLoop: label before the for statement.

Suggested change
for {
keepaliveLoop: for {

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc1bd55593

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +76 to +80
case _, ok := <-ch:
if !ok {
break keepaliveLoop
}
timer.Reset(keepaliveTimeout)

Choose a reason for hiding this comment

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

P2 Badge Drain/stop timer before Reset to avoid spurious timeout

If a keepalive response arrives after the timer has already fired but before timer.C is selected, the select can take the keepalive branch and call timer.Reset without stopping/draining the timer. In Go, resetting an expired timer without first stopping and draining its channel can leave timer.C readable, causing the next iteration to hit the timeout case immediately and exit even though a keepalive just arrived. This would make the session incorrectly expire under tight timing races; the design should mention stopping/draining before reset or using a time.AfterFunc/time.NewTicker pattern.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants