Skip to content
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

client: fix connection persistence bug #1938

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-pears-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@penumbra-zone/client': minor
---

attempt to reconnect on broken client connection
20 changes: 19 additions & 1 deletion packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { PenumbraManifest } from './manifest.js';
import { PenumbraProvider } from './provider.js';
import { PenumbraState } from './state.js';
import { PenumbraRequestFailure } from './error.js';

const isLegacyProvider = (
provider: PenumbraProvider,
Expand Down Expand Up @@ -188,7 +189,24 @@ export class PenumbraClient {
await this.attach(providerOrigin);
}
this.connection ??= this.createConnection();
await this.connection.port;

// Connection timeouts, provider detachments, etc. appear similar to a connection denial.
// Explicitly handle denial errors and propagate them back to the caller. Without this,
// a denied connection would immediately trigger an attempt to re-establish the connection.
try {
await this.connection.port;
} catch (error) {
if (error instanceof Error && error.cause) {
if (error.cause === PenumbraRequestFailure.Denied) {
throw error;
}
}

// Clean up dangling connection resources and attempt to establish reconnection
this.destroyConnection();
Comment on lines +205 to +206
Copy link
Contributor Author

@TalDerei TalDerei Dec 10, 2024

Choose a reason for hiding this comment

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

Is this sufficient for ensuring no dangling connection resources persist?

this.connection = this.createConnection();
await this.connection.port;
}
}

/** Call `disconnect` on the associated provider to release connection
Expand Down