Repository navigation
fix(warehouse): write Snowflake reconnects to the log #1427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * A driver replacing a connection the warehouse closed (today: Snowflake after an idle | ||
| * timeout, a network drop or laptop sleep). The reopen is silent to the caller, which is | ||
| * the point, but without these events it was also missing from the log: a session that | ||
| * kept dropping looked exactly like one that never did. | ||
| */ | ||
| export interface ReconnectEvent { | ||
| warehouse: string | ||
| /** Identifies which account the connection belongs to, e.g. the Snowflake account locator. */ | ||
| account?: string | ||
| phase: "started" | "reconnected" | "failed" | ||
| /** How the closed session showed: the SDK reported it down before a statement, or a statement failed because | ||
| * the session had closed. The second does not say the statement did not run: a write may already have. */ | ||
| reason: "connection-down" | "closed-during-statement" | ||
| /** From the start of the reconnect. On `reconnected` and `failed`. */ | ||
| durationMs?: number | ||
| /** Session settings (USE, SET, ALTER SESSION…) restored on the new session. On `reconnected`. */ | ||
| settingsRestored?: number | ||
| /** Temporary objects or an open transaction went with the old session, or a statement that could create them | ||
| * was still running on it, so whether they did is not known yet. On `reconnected`. */ | ||
| sessionStateLost?: boolean | ||
| /** On `failed`. Never carries the session's statements (a replayed setting can hold anything the user ran). */ | ||
| error?: string | ||
| } | ||
|
|
||
| type Listener = (event: ReconnectEvent) => void | Promise<void> | ||
|
|
||
| // Process-global, for the same reason as the sign-in notices: the driver and its | ||
| // subscriber can be loaded through different module graphs. | ||
| const LISTENERS_KEY = Symbol.for("altimate.drivers.reconnectListeners") | ||
| const listeners: Set<Listener> = ((globalThis as Record<symbol, unknown>)[LISTENERS_KEY] as Set<Listener>) ?? | ||
| ((globalThis as Record<symbol, unknown>)[LISTENERS_KEY] = new Set<Listener>()) | ||
|
|
||
| /** Subscribe to reconnect events from every driver. Returns the unsubscribe. */ | ||
| export function onReconnect(listener: Listener): () => void { | ||
| listeners.add(listener) | ||
| return () => listeners.delete(listener) | ||
| } | ||
|
|
||
| export function emitReconnect(event: ReconnectEvent): void { | ||
| for (const listener of listeners) { | ||
| // A broken listener, sync or async, must not fail the reconnect or leave an unhandled rejection. | ||
| try { | ||
| void Promise.resolve(listener(event)).catch(() => {}) | ||
| } catch { | ||
| // as above | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: A closed-session error removes this count before
executeQuerystarts reconnecting, so the event can reportsessionStateLost: falsefor a stateful statement Snowflake may already have accepted. Preserve the in-flight marker through the reconnect loss snapshot on this error path.Prompt for AI agents