Revert "fix(service-party-app): joinSession 添加重试逻辑处理乐观锁冲突"

This reverts commit 8c3a299714.
This commit is contained in:
hailin 2025-12-29 13:48:14 -08:00
parent 8c3a299714
commit 66c3cec9a5
1 changed files with 1 additions and 49 deletions

View File

@ -436,54 +436,13 @@ export class GrpcClient extends EventEmitter {
}
/**
*
*
*
*
*/
async joinSession(sessionId: string, partyId: string, joinToken: string): Promise<JoinSessionResponse> {
if (!this.client) {
throw new Error('Not connected');
}
const maxRetries = 3;
const baseDelayMs = 500;
let lastError: Error | null = null;
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const result = await this.doJoinSession(sessionId, partyId, joinToken);
return result;
} catch (err) {
lastError = err as Error;
const errorMessage = lastError.message || '';
// 判断是否为可重试的错误
const isRetryable =
errorMessage.includes('optimistic lock') ||
errorMessage.includes('modified by another transaction') ||
errorMessage.includes('UNAVAILABLE') ||
errorMessage.includes('DEADLINE_EXCEEDED');
if (!isRetryable || attempt >= maxRetries) {
console.error(`[gRPC] joinSession failed after ${attempt} attempt(s):`, errorMessage);
throw lastError;
}
// 计算退避延迟(指数退避 + 随机抖动)
const delay = baseDelayMs * Math.pow(2, attempt - 1) + Math.random() * 100;
console.log(`[gRPC] joinSession attempt ${attempt}/${maxRetries} failed (${errorMessage}), retrying in ${Math.round(delay)}ms...`);
await this.sleep(delay);
}
}
throw lastError || new Error('joinSession failed after retries');
}
/**
* joinSession
*/
private doJoinSession(sessionId: string, partyId: string, joinToken: string): Promise<JoinSessionResponse> {
return new Promise((resolve, reject) => {
(this.client as grpc.Client & { joinSession: (req: unknown, callback: (err: Error | null, res: JoinSessionResponse) => void) => void })
.joinSession(
@ -503,13 +462,6 @@ export class GrpcClient extends EventEmitter {
});
}
/**
*
*/
private sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
/**
*
*/