Skip to content

Commit

Permalink
Merge pull request #4105 from WalletConnect/fix/session-settle-race-cond
Browse files Browse the repository at this point in the history
fix: saves `session` object before sending `sessionSettle` request
  • Loading branch information
ganchoradkov authored Jan 8, 2024
2 parents 7b8942c + b5bd53a commit eeaa990
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/sign-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ export class Engine extends IEngine {
...(sessionProperties && { sessionProperties }),
};
await this.client.core.relayer.subscribe(sessionTopic);
await this.sendRequest({
topic: sessionTopic,
method: "wc_sessionSettle",
params: sessionSettle,
throwOnFailedPublish: true,
});
const session = {
...sessionSettle,
topic: sessionTopic,
Expand All @@ -286,6 +280,21 @@ export class Engine extends IEngine {
controller: selfPublicKey,
};
await this.client.session.set(sessionTopic, session);
try {
await this.sendRequest({
topic: sessionTopic,
method: "wc_sessionSettle",
params: sessionSettle,
throwOnFailedPublish: true,
});
} catch (error) {
this.client.logger.error(error);
// if the publish fails, delete the session and throw an error
this.client.session.delete(sessionTopic, getSdkError("USER_DISCONNECTED"));
await this.client.core.relayer.unsubscribe(sessionTopic);
throw error;
}

await this.setExpiry(sessionTopic, calcExpiry(SESSION_EXPIRY));
return {
topic: sessionTopic,
Expand Down

0 comments on commit eeaa990

Please sign in to comment.