Skip to content

[SDK] fix: clear inflightRequests after each batch RPC call #5872

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 1 commit into from
Jan 3, 2025
Merged
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
41 changes: 18 additions & 23 deletions packages/thirdweb/src/rpc/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,46 +138,41 @@
requestTimeoutMs: options.config?.requestTimeoutMs,
})
.then((responses) => {
// for each response, resolve the inflight request
activeBatch.forEach((inflight, index) => {
// Handle the inflight request promise for each response.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes are just comments and re-arranging the if statements into if-else's.

const response = responses[index];
// if we didn't get a response at all, reject the inflight request

// No response.
if (!response) {
inflight.reject(new Error("No response"));
return;
}
// handle errors in the response
if (response instanceof Error) {
// Response is an error or error string.
else if (response instanceof Error) {
inflight.reject(response);
return;
}

// handle strings as responses??
if (typeof response === "string") {
} else if ("error" in response) {
inflight.reject(response.error);
} else if (typeof response === "string") {
inflight.reject(new Error(response));
return;
}

if ("error" in response) {
inflight.reject(response.error);
// otherwise, resolve the inflight request
} else if (response.method === "eth_subscription") {
// TODO: handle subscription responses
throw new Error("Subscriptions not supported yet");
} else {
// eth_subscription is not supported yet.
else if (response.method === "eth_subscription") {
inflight.reject("Subscriptions not supported yet");
}

Check warning on line 160 in packages/thirdweb/src/rpc/rpc.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/rpc/rpc.ts#L159-L160

Added lines #L159 - L160 were not covered by tests
// Else return the successful response for the inflight request.
else {
inflight.resolve(response.result);
}
// remove the inflight request from the inflightRequests map
inflightRequests.delete(inflight.requestKey);
});
})
.catch((err) => {
// http call failed, reject all inflight requests
for (const inflight of activeBatch) {
inflight.reject(err);
// remove the inflight request from the inflightRequests map
inflightRequests.delete(inflight.requestKey);
}
})
.finally(() => {
// Clear the inflight requests map so any new requests are re-fetched.
inflightRequests.clear();
});
}

Expand Down
Loading