Skip to content

fix(server): fix the ephemeral key leak by non-atomic operation#742

Merged
merlimat merged 18 commits intomainfrom
fix.leak.ephemeral
Aug 27, 2025
Merged

fix(server): fix the ephemeral key leak by non-atomic operation#742
merlimat merged 18 commits intomainfrom
fix.leak.ephemeral

Conversation

@mattisonchao
Copy link
Copy Markdown
Member

@mattisonchao mattisonchao commented Aug 26, 2025

Motivation

A non-atomic operation will leak some ephemeral keys if the new KV is put after the session list.

Modification

  • Make the session index/ephemeral keys cleanup become an atomic operation.
  • Pass the notification into the DB callback.

@mattisonchao mattisonchao self-assigned this Aug 26, 2025
@mattisonchao mattisonchao marked this pull request as draft August 26, 2025 14:49
@mattisonchao mattisonchao marked this pull request as ready for review August 26, 2025 15:22
Copy link
Copy Markdown
Collaborator

@merlimat merlimat left a comment

Choose a reason for hiding this comment

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

Looks good


// WithSessionKeepAliveTicker is an internal API used to control the duration
// of the session keep-alive ticker. This is for experimental use only.
func WithSessionKeepAliveTicker(ticker time.Duration) ClientOption {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wouldn't expose this in API (even if comment says it's internal). We should be able to modify the value by accessing the private variable in the tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved the test into the oxia package and made the WithSessionKeepAliveTicker private.

if _, err := deleteShadow(batch, notification, key, entry); err != nil {
return err
}
if IsSessionKey(key) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit:

if !IsSessionKey(key) {
    return nil;
}
....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed.

@mattisonchao mattisonchao requested a review from merlimat August 27, 2025 00:17
@RobertIndie RobertIndie requested a review from Copilot August 27, 2025 10:04

This comment was marked as outdated.

@mattisonchao mattisonchao requested a review from Copilot August 27, 2025 12:49

This comment was marked as outdated.

@mattisonchao mattisonchao requested a review from Copilot August 27, 2025 13:41

This comment was marked as outdated.

@mattisonchao mattisonchao requested a review from Copilot August 27, 2025 13:58

This comment was marked as outdated.

@mattisonchao mattisonchao requested a review from Copilot August 27, 2025 14:00
Copy link
Copy Markdown
Contributor

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 addresses an ephemeral key leak caused by non-atomic operations in session cleanup. The fix ensures that session cleanup operations (including ephemeral key deletion) are performed atomically within the database transaction.

  • Refactored session deletion to be atomic by moving ephemeral key cleanup into database callbacks
  • Updated all UpdateOperationCallback interfaces to accept notification parameter for proper event handling
  • Added comprehensive test coverage for the session key leak scenario

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/session_manager.go Core fix implementing atomic session cleanup and ephemeral key deletion within DB callbacks
server/session.go Simplified session deletion to rely on atomic DB operations instead of manual cleanup
server/secondary_indexes.go Updated wrapper callbacks to pass notifications parameter through the callback chain
server/kv/db.go Modified UpdateOperationCallback interface to include notifications parameter
server/kv/notifications_tracker.go Made Notifications struct public for use in callback interfaces
server/session_manager_test.go Updated tests to match new callback signatures and added IsSessionKey validation tests
server/kv/db_test.go Updated test callback to match new interface signature
oxia/sessions.go Updated session keep-alive logic to use configurable ticker instead of hardcoded calculation
oxia/session_test.go Added integration test to verify the ephemeral key leak fix
oxia/options_client.go Added internal option for configuring session keep-alive ticker duration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@merlimat merlimat merged commit 6b60eb4 into main Aug 27, 2025
10 of 11 checks passed
@merlimat merlimat deleted the fix.leak.ephemeral branch August 27, 2025 17:23
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.

3 participants