Skip to content

feat(bigtable): add config manager in bidi package#14552

Open
sushanb wants to merge 2 commits into
googleapis:mainfrom
sushanb:config_manager
Open

feat(bigtable): add config manager in bidi package#14552
sushanb wants to merge 2 commits into
googleapis:mainfrom
sushanb:config_manager

Conversation

@sushanb
Copy link
Copy Markdown
Contributor

@sushanb sushanb commented May 7, 2026

No description provided.

@sushanb sushanb requested a review from nimf May 7, 2026 20:36
@sushanb sushanb requested review from a team as code owners May 7, 2026 20:36
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label May 7, 2026
Copy link
Copy Markdown
Contributor

@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 introduces a ConfigManager to handle fetching and periodically polling client configurations from the Bigtable server, including logic for probabilistic session routing. Feedback identifies a potential goroutine leak in StartPolling due to overwriting the cancel function, suggests refactoring ShouldUseSession to use internal state for idiomatic consistency, and recommends adding a timeout to the GetClientConfiguration RPC call to prevent indefinite blocking.

Comment on lines +49 to +55
requestParamsMD := metadata.Pairs(requestParamsHeader,
fmt.Sprintf("name=%s&app_profile_id=%s", url.QueryEscape(instanceName), url.QueryEscape(appProfileId)))

originalContextMd, _ := metadata.FromOutgoingContext(ctx)
ctx = metadata.NewOutgoingContext(ctx, metadata.Join(originalContextMd, requestParamsMD))

return m.client.GetClientConfiguration(ctx, req)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Calling StartPolling multiple times will overwrite the m.cancel function, leading to a leak of previous polling goroutines because they can no longer be stopped via Close(). Additionally, the goroutine should ensure m.cancel is cleared upon exit so that polling can be restarted if needed. The suggested fix uses a lock to prevent concurrent starts and ensures the field is cleared upon exit, while avoiding performing any slow operations while holding the exclusive lock.

func (m *ConfigManager) StartPolling(ctx context.Context, instanceName, appProfileId string) {
	m.mu.Lock()
	if m.cancel != nil {
		m.mu.Unlock()
		return
	}
	pollCtx, cancel := context.WithCancel(ctx)
	m.cancel = cancel
	m.mu.Unlock()

	go func() {
		defer func() {
			cancel()
			m.mu.Lock()
			m.cancel = nil
			m.mu.Unlock()
		}()
References
  1. Avoid performing slow operations, such as gRPC channel creation, while holding an exclusive lock, as this can block other operations and slow down the entire client.

Comment on lines +35 to +42
}

// NewConfigManager creates a new ConfigManager.
func NewConfigManager(client btpb.BigtableClient) *ConfigManager {
return &ConfigManager{client: client}
}

// GetClientConfiguration fetches the client configuration from the server.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

ShouldUseSession is defined as a method on ConfigManager but it doesn't use the manager's internal state, requiring the caller to pass the config manually. It would be more idiomatic for the manager to provide a parameterless ShouldUseSession() method that uses m.currentConfig. Avoid converting this to a standalone helper function to maintain API consistency and follow repository patterns.

References
  1. Avoid redundant top-level functions if a similar method exists on a struct, especially if it leads to API inconsistency or deviates from parity with other SDKs.


// ConfigManager handles fetching and applying client configuration.
type ConfigManager struct {
client btpb.BigtableClient
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The RPC call to GetClientConfiguration lacks a timeout. If the network hangs, the polling goroutine could be blocked indefinitely. Ensure the RPC's context is tied to a lifecycle with a timeout to prevent resource leaks or long delays.

References
  1. Propagate the RPC's context to factory calls that create new gRPC connections to ensure that connection attempts are tied to the RPC's lifecycle and can be cancelled or timed out, preventing resource leaks or long delays.

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

Labels

api: bigtable Issues related to the Bigtable API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant