Skip to content

Commit

Permalink
Fix: Fallback to RPC in more cases when reconcile stream errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayprabhu committed Nov 7, 2024
1 parent 3ae52bc commit 5b57a40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-deers-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/shuttle": patch
---

fix: Make fallback to rpc in more cases when reconcile stream errors
21 changes: 11 additions & 10 deletions packages/shuttle/src/shuttle/messageReconciliation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,23 @@ export class MessageReconciliation {
) {
const id = randomUUID();
const result = new Promise<HubResult<MessagesResponse>>((resolve) => {
// Do not allow hanging unresponsive connections to linger:
const cancel = setTimeout(
() => resolve(err(new HubError("unavailable", "server timeout"))),
this.connectionTimeout,
);

if (!this.stream) {
fallback()
.then((result) => resolve(result))
.finally(() => clearTimeout(cancel));
fallback().then((result) => resolve(result));
return;
}
const process = async (response: StreamFetchResponse) => {
// Do not allow hanging unresponsive connections to linger:
const cancel = setTimeout(() => {
this.log.warn("Stream fetch timed out, falling back to RPC");
this.stream?.cancel();
this.stream = undefined;
fallback().then((result) => resolve(result));
}, this.connectionTimeout);

if (!this.stream) {
clearTimeout(cancel);
resolve(err(new HubError("unavailable", "unexpected stream termination")));
this.log.warn("Stream unavailable, falling back to RPC");
fallback().then((result) => resolve(result));
return;
}
this.stream.off("data", process);
Expand Down

0 comments on commit 5b57a40

Please sign in to comment.