fix: recover auction client from rejected transitions
거부(특히 낙관적 동시성 CONFLICT)를 받은 클라가 낡은 상태에 멈춰 후속 액션을 반복 거부받던 문제를 해결한다. - 서버: 거부 ack에 설명적 거부코드(auctionRejectionReason)와 resync 권장 여부, 그리고 resync 권장 거부에 한해 최신 권위 state를 동봉한다. 구조 전환 거부는 내부 code(CONFLICT 등)를 구조화해 던져 매핑 가능하게 한다. - 클라: 거부 시 동봉된 state로 즉시 rebaseline(없으면 join으로 재요청)하고, "낡은 화면" 거부면 구조 액션을 1회 자동 재시도한다. 거부 문구를 거부코드 기반 한국어로 매핑한다(error 이벤트 채널 포함). 신규 auction-rejection 모듈로 짧은 내부 코드를 맥락이 담긴 설명적 코드로 변환한다. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
09d304d782
commit
55b80e62cd
6 files changed
+477
-15
No files matched your search
@@ -31,6 +31,10 @@ import type {
|
||||
AuctionStateResponse,
|
||||
} from './auction.service';
|
||||
import { AuctionEventBusService } from './auction-event-bus.service';
|
||||
import {
|
||||
isAuctionResyncRecommended,
|
||||
resolveAuctionRejectionReason,
|
||||
} from './auction-rejection';
|
||||
import type { MatchSideEffectDelta } from './auction-side-effect.service';
|
||||
import { serializeRealtimeAuction } from './auction-realtime-serializer';
|
||||
import { AuctionRedisService } from './redis/auction-redis.service';
|
||||
@@ -211,11 +215,14 @@ export class AuctionGateway
|
||||
),
|
||||
});
|
||||
} catch (error) {
|
||||
const errorPayload = this.resolveErrorPayload(error);
|
||||
const bidServerTiming = this.extractBidServerTiming(errorPayload);
|
||||
this.emitError(socket, errorPayload.message);
|
||||
const rejectionAckFields = await this.resolveRejectionAckFields(
|
||||
matchId,
|
||||
error,
|
||||
);
|
||||
const bidServerTiming = this.extractBidServerTiming(rejectionAckFields);
|
||||
this.emitError(socket, String(rejectionAckFields.message ?? ''));
|
||||
ack?.({
|
||||
...errorPayload,
|
||||
...rejectionAckFields,
|
||||
bidRequestId,
|
||||
bidServerTiming: this.buildGatewayBidTiming(
|
||||
gatewayBidStartedAtMS,
|
||||
@@ -276,8 +283,8 @@ export class AuctionGateway
|
||||
} catch (error) {
|
||||
this.emitKnownError(socket, error);
|
||||
ack?.({
|
||||
...(await this.resolveRejectionAckFields(matchId, error)),
|
||||
auctionActionRequestId: payload?.auctionActionRequestId,
|
||||
code: error instanceof Error ? error.message : 'UNKNOWN',
|
||||
rejected: true,
|
||||
});
|
||||
}
|
||||
@@ -306,8 +313,8 @@ export class AuctionGateway
|
||||
} catch (error) {
|
||||
this.emitKnownError(socket, error);
|
||||
ack?.({
|
||||
...(await this.resolveRejectionAckFields(matchId, error)),
|
||||
auctionActionRequestId: payload?.auctionActionRequestId,
|
||||
code: error instanceof Error ? error.message : 'UNKNOWN',
|
||||
rejected: true,
|
||||
});
|
||||
}
|
||||
@@ -335,8 +342,8 @@ export class AuctionGateway
|
||||
} catch (error) {
|
||||
this.emitKnownError(socket, error);
|
||||
ack?.({
|
||||
...(await this.resolveRejectionAckFields(matchId, error)),
|
||||
auctionActionRequestId: payload?.auctionActionRequestId,
|
||||
code: error instanceof Error ? error.message : 'UNKNOWN',
|
||||
rejected: true,
|
||||
});
|
||||
}
|
||||
@@ -364,8 +371,8 @@ export class AuctionGateway
|
||||
} catch (error) {
|
||||
this.emitKnownError(socket, error);
|
||||
ack?.({
|
||||
...(await this.resolveRejectionAckFields(matchId, error)),
|
||||
auctionActionRequestId: payload?.auctionActionRequestId,
|
||||
code: error instanceof Error ? error.message : 'UNKNOWN',
|
||||
rejected: true,
|
||||
});
|
||||
}
|
||||
@@ -608,6 +615,49 @@ export class AuctionGateway
|
||||
return JSON.parse(JSON.stringify(auction));
|
||||
}
|
||||
|
||||
/**
|
||||
* 거부 ack에 실을 공통 필드를 만든다.
|
||||
*
|
||||
* - `code`/`message`: 기존 내부 코드/문구(진단·하위호환).
|
||||
* - `auctionRejectionReason`: 맥락을 담은 설명적 거부코드(클라가 문구로 매핑).
|
||||
* - `resyncRecommended`: "내가 본 상태가 낡았다"는 신호면 true.
|
||||
* - `state`: resync 권장 거부에 한해 최신 권위 state를 동봉해, 클라가 join
|
||||
* 왕복 없이 즉시 rebaseline하도록 한다(후속 액션의 반복 CONFLICT 차단).
|
||||
*/
|
||||
private async resolveRejectionAckFields(
|
||||
matchId: string,
|
||||
error: unknown,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const errorPayload = this.resolveErrorPayload(error);
|
||||
const auctionRejectionReason = resolveAuctionRejectionReason(
|
||||
typeof errorPayload.code === 'string' ? errorPayload.code : undefined,
|
||||
errorPayload.message,
|
||||
);
|
||||
const resyncRecommended = isAuctionResyncRecommended(auctionRejectionReason);
|
||||
const state = resyncRecommended
|
||||
? await this.fetchSerializedAuctionState(matchId)
|
||||
: undefined;
|
||||
return {
|
||||
...errorPayload,
|
||||
auctionRejectionReason,
|
||||
resyncRecommended,
|
||||
...(state ? { state } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
private async fetchSerializedAuctionState(
|
||||
matchId: string,
|
||||
): Promise<Record<string, unknown> | undefined> {
|
||||
try {
|
||||
const state = await this.auctionService.getStateByMatchId(
|
||||
new mongoose.Types.ObjectId(matchId),
|
||||
);
|
||||
return state ? this.serializeAuction(state) : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private resolveErrorPayload(error: unknown): Record<string, unknown> & {
|
||||
message: string;
|
||||
} {
|
||||
|
||||
Reference in new issue
Block a user