Skip to content

Avoid parsing the connection string multiple times in the auth path #580

@bewithgaurav

Description

@bewithgaurav

What

The connection string gets parsed by _ConnectionStringParser more than once on every connect when Entra ID auth is in play.

For one Entra ID connect today:

  1. Connection.__init__ calls _construct_connection_string, which parses once.
  2. process_connection_string (in auth.py) splits the string again to pick out auth params.
  3. For MSI with UID, _extract_msi_client_id parses it a third time via _ConnectionStringParser.

Same string, three parses. Small per-connect cost, but it's wasted work and it's also why auth.py keeps reimplementing parsing instead of trusting the canonical parser.

Why fix it

  • Removes redundant work on the connect path.
  • Lets auth.py stop hand-rolling its own parsing (the naive split(";") in process_connection_string and extract_auth_type only exists because the parsed map isn't available at that point).
  • Makes the bracing-value bug ([separate issue](TBD link)) trivial to fix as a side effect.

Suggested approach

  1. Connection.__init__ already produces a parsed map via _construct_connection_string. Hold on to it (or re-run the parser once and pass the dict around).
  2. Change process_connection_string (and extract_auth_type, and _extract_msi_client_id) to take the parsed dict instead of the raw string. Read keys from the dict directly.
  3. Build the sanitized output via _ConnectionStringBuilder from the same dict (minus the sensitive keys).

Same call shape from the outside, one parse instead of three, and auth.py stops carrying its own mini-parser.

Workaround mentioned in the review

A connection-string → uid hashmap was suggested as an ad-hoc fix. Skipping it because it has its own concurrency and lifecycle problems and doesn't address the deeper "auth.py shouldn't reparse" issue.

Background

Surfaced during PR #573 review.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesttriage doneIssues that are triaged by dev team and are in investigation.triage neededFor new issues, not triaged yet.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions