Skip to content

Conversation

matthewdale
Copy link
Collaborator

@matthewdale matthewdale commented Aug 22, 2025

GODRIVER-3612

Summary

Add an internal-only API mongo.NewSessionWithID that returns a *Session for the specified Client and session ID document.

Background & Motivation

Copy link
Contributor

API Change Report

No changes found!

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Aug 22, 2025

🧪 Performance Results

Commit SHA: 9eb374b

There were no significant changes to the performance to report for version 68a8bb56eaf3ce00070ac5e4.

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

@matthewdale matthewdale force-pushed the godriver3612-session-with-id branch from bc7a505 to 9eb374b Compare August 22, 2025 18:47
@matthewdale matthewdale added review-priority-normal Medium Priority PR for Review: within 1 business day feature ignore-for-release labels Aug 27, 2025
@matthewdale matthewdale marked this pull request as ready for review August 27, 2025 01:47
@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 01:47
@matthewdale matthewdale requested a review from a team as a code owner August 27, 2025 01:47
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.

Pull Request Overview

This PR adds an internal-only API mongo.NewSessionWithID that creates a *Session for a specified Client and session ID document. This API is intended for internal use cases where specific session IDs need to be used rather than letting the driver generate them automatically.

  • Introduces NewSessionWithID function that constructs sessions with custom session ID documents
  • Implements build tag protection (//go:build mongointernal) to restrict usage to internal builds only
  • Updates CI configuration to enable the mongointernal build tag in tests

Reviewed Changes

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

File Description
mongo/mongointernal.go Implements the new NewSessionWithID API with proper documentation and build tag restrictions
internal/integration/mongointernal_test.go Adds comprehensive tests covering both successful usage and expected panic behavior
.evergreen/config.yml Updates CI build tags to include mongointernal for proper test execution

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

@matthewdale matthewdale requested review from prestonvasquez and removed request for qingyang-hu August 27, 2025 01:48
Copy link
Member

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

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

I'm concerned about users using session.Client methods that involve a pool. Or worse, maintainers adding a new method to session.Client that requires accessing the pool and forgetting to document that behavior for NewSessionWithID.

I've created GODRIVER-3649 to follow up on this in 3.0.

//
// NewSessionWithID is intended only for internal use and may be changed or
// removed at any time.
func NewSessionWithID(client *Client, sessionID bson.Raw) *Session {
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[nit] Suggest renaming this function to NewSessionWithLSID

// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

//go:build mongointernal
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[non-blocking] Should we name this mongointernal_lsid to keep it separate from any future code we may want to gate behind a mongointernal build tag?

mt.Parallel()

sessionID := bson.Raw(bsoncore.NewDocumentBuilder().
AppendBinary("id", 4, []byte{}).
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[nit] Suggest using a valid 16-byte UUID to ensure the panic is due to the session being unpooled and not an invalid LSID.

// subtype 4).
//
// Sessions returned by NewSessionWithID are never added to the driver's session
// pool. Calling EndSession on a Session returned by NewSessionWithID will
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[non-blocking] We should include SetServer as API that will panic. I'm not sure why anyone would use it and AFAIK it's only use case happens for implicit sessions, but it's still possible:

sess.Client().SetSrerver() // will panic 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ignore-for-release review-priority-normal Medium Priority PR for Review: within 1 business day
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants