Skip to content

fix(go): process URI before other options to avoid nondeterminism#142

Closed
ewgenius wants to merge 1 commit intoadbc-drivers:mainfrom
spiceai:evgenii/fix-auth-options-go
Closed

fix(go): process URI before other options to avoid nondeterminism#142
ewgenius wants to merge 1 commit intoadbc-drivers:mainfrom
spiceai:evgenii/fix-auth-options-go

Conversation

@ewgenius
Copy link
Copy Markdown
Contributor

@ewgenius ewgenius commented Mar 24, 2026

Problem

When BigQueryDatabaseInit is called with both a uri and explicit auth options (e.g. adbc.bigquery.sql.auth_type, adbc.bigquery.sql.auth_credentials), the connection intermittently fails with:

Could not create client: bigquery: constructing client: credentials: could not find default credentials

The failure is non-deterministic - the same set of options may succeed on one call and fail on the next.

Root cause: databaseImpl.SetOptions iterates a map[string]string, which has non-deterministic order in Go. "uri" is the only macro key in the options set - ParseBigQueryURIToParams expands it into multiple fields and unconditionally sets auth_type = ADC when the URI contains no OAuthType query parameter (e.g. a plain bigquery:///project-id). All other keys are simple independent field writes. When the map iteration happened to visit "uri" after the explicit auth options, the URI parser silently overwrote the caller's auth_type back to ADC. newClient() then skipped the provided credentials entirely and fell through to Application Default Credentials discovery.

Solution

Fix SetOptions to always process "uri" first, before iterating the rest of the options. Since "uri" is the only key with expansion side-effects, this single ordering guarantee is sufficient - all other keys are independent field writes and their relative order does not matter.

ParseBigQueryURIToParams is unchanged: a URI without OAuthType still correctly defaults to ADC for callers who provide only a URI with no explicit auth options.

Copy link
Copy Markdown
Contributor

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

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

Good catch, thank you!

@lidavidm lidavidm changed the title fix: explicit auth options randomly discarded when URI is provided alongside them fix: process URI before other options to avoid nondeterminism Mar 25, 2026
@github-actions
Copy link
Copy Markdown

@lidavidm lidavidm changed the title fix: process URI before other options to avoid nondeterminism fix(go): process URI before other options to avoid nondeterminism Mar 25, 2026
@lidavidm
Copy link
Copy Markdown
Contributor

GitHub seems to be broken, despite the all-green status page...
image

@lidavidm
Copy link
Copy Markdown
Contributor

GitHub still won't let me merge this. @ewgenius do you mind re-creating the PR?

@ewgenius
Copy link
Copy Markdown
Contributor Author

@lidavidm sure, I'll recreate

@ewgenius
Copy link
Copy Markdown
Contributor Author

@lidavidm I've created new one #143

@ewgenius ewgenius closed this Mar 26, 2026
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.

2 participants