fix(auction): prevent skipped players and incomplete completion
This commit is contained in:
1 parent
de84ad5309
commit
5bc748dc4d
10 files changed
+677
-32
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import type { ApiAuction } from './types';
|
||||
|
||||
type AuctionActionState = Pick<
|
||||
ApiAuction,
|
||||
| 'auctionLifecycleId'
|
||||
| 'currentAuctionPlayerOrderIndex'
|
||||
| 'currentBidRoundPlayerUserId'
|
||||
| 'phase'
|
||||
| 'revision'
|
||||
>;
|
||||
|
||||
interface AuctionActionObservation {
|
||||
clientObservedAuctionLifecycleId?: string;
|
||||
clientObservedCurrentAuctionPlayerOrderIndex?: number;
|
||||
clientObservedCurrentBidRoundPlayerUserId?: string;
|
||||
clientObservedPhase?: string;
|
||||
clientObservedRevision?: number;
|
||||
}
|
||||
|
||||
export function resolveAuctionActionRejection(
|
||||
params: Parameters<typeof shouldRetryAuctionAction>[0],
|
||||
): { applyServerState: boolean; retry: boolean } {
|
||||
const { request, currentState, serverState } = params;
|
||||
// Decide from the live screen before applying the ACK: an old response may force resync.
|
||||
const applyServerState = Boolean(
|
||||
currentState &&
|
||||
serverState &&
|
||||
request.clientObservedAuctionLifecycleId &&
|
||||
currentState.auctionLifecycleId ===
|
||||
request.clientObservedAuctionLifecycleId &&
|
||||
(serverState.auctionLifecycleId !== currentState.auctionLifecycleId ||
|
||||
(Number.isSafeInteger(serverState.revision) &&
|
||||
(serverState.revision ?? -1) > (currentState.revision ?? -1))),
|
||||
);
|
||||
return { applyServerState, retry: shouldRetryAuctionAction(params) };
|
||||
}
|
||||
|
||||
export function shouldRetryAuctionAction(params: {
|
||||
action: string;
|
||||
request: AuctionActionObservation;
|
||||
serverState?: AuctionActionState | null;
|
||||
currentState?: AuctionActionState | null;
|
||||
resyncRecommended: boolean;
|
||||
retryAttempt: number;
|
||||
}): boolean {
|
||||
const { action, request, serverState, currentState } = params;
|
||||
if (
|
||||
!params.resyncRecommended ||
|
||||
params.retryAttempt >= 1 ||
|
||||
!serverState ||
|
||||
!currentState
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const phase = request.clientObservedPhase;
|
||||
const phaseAllowsAction =
|
||||
(action === 'next' && (phase === 'sold' || phase === 'passed')) ||
|
||||
(action === 'open-bidding' && phase === 'presenting') ||
|
||||
((action === 'sold' || action === 'passed') && phase === 'bidding');
|
||||
if (
|
||||
!phaseAllowsAction ||
|
||||
!request.clientObservedAuctionLifecycleId ||
|
||||
!request.clientObservedCurrentBidRoundPlayerUserId ||
|
||||
!Number.isSafeInteger(
|
||||
request.clientObservedCurrentAuctionPlayerOrderIndex,
|
||||
) ||
|
||||
(request.clientObservedCurrentAuctionPlayerOrderIndex ?? -1) < 0 ||
|
||||
!Number.isSafeInteger(request.clientObservedRevision) ||
|
||||
(request.clientObservedRevision ?? -1) < 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A delayed rejection must not turn the original action into one for another player.
|
||||
return [serverState, currentState].every(
|
||||
(state) =>
|
||||
state.auctionLifecycleId === request.clientObservedAuctionLifecycleId &&
|
||||
state.currentAuctionPlayerOrderIndex ===
|
||||
request.clientObservedCurrentAuctionPlayerOrderIndex &&
|
||||
state.currentBidRoundPlayerUserId ===
|
||||
request.clientObservedCurrentBidRoundPlayerUserId &&
|
||||
state.phase === phase &&
|
||||
Number.isSafeInteger(state.revision) &&
|
||||
(state.revision ?? -1) >= request.clientObservedRevision!,
|
||||
);
|
||||
}
|
||||
@@ -14,11 +14,13 @@
|
||||
const REASON_TO_USER_MESSAGE: Record<string, string> = {
|
||||
// 구조 전환
|
||||
AUCTION_TRANSITION_REJECTED_BECAUSE_LIVE_STATE_CHANGED_BEFORE_APPLY:
|
||||
'경매 상태가 바뀌어 최신 상태로 맞췄어요. 다시 시도해 주세요.',
|
||||
'경매 상태가 바뀌었어요. 현재 선수와 진행 상태를 확인해 주세요.',
|
||||
AUCTION_TRANSITION_REJECTED_BECAUSE_AUCTION_NOT_IN_BIDDING_PHASE:
|
||||
'이미 입찰 단계가 아니에요. 최신 상태로 맞췄어요.',
|
||||
AUCTION_TRANSITION_REJECTED_BECAUSE_PHASE_DOES_NOT_ALLOW_ADVANCE:
|
||||
'이미 다음 단계로 넘어간 상태예요. 최신 상태로 맞췄어요.',
|
||||
'현재 단계에서는 다음 선수로 넘어갈 수 없어요. 현재 선수를 확인해 주세요.',
|
||||
AUCTION_TRANSITION_REJECTED_BECAUSE_ROSTER_INVALID:
|
||||
'팀 배정 상태를 확인해야 해 경매를 완료하지 못했습니다.',
|
||||
AUCTION_TRANSITION_REJECTED_BECAUSE_NO_WINNING_BID_TO_MARK_SOLD:
|
||||
'낙찰할 입찰이 없어요. 최신 상태로 맞췄어요.',
|
||||
AUCTION_TRANSITION_REJECTED_BECAUSE_ACTIVE_BID_PRESENT:
|
||||
@@ -56,7 +58,9 @@ const ENGLISH_MESSAGE_TO_USER_MESSAGE: Record<string, string> = {
|
||||
'Unknown team.': '알 수 없는 팀이에요.',
|
||||
'Bid request conflicts with an earlier request.': '중복된 요청이에요.',
|
||||
'Cannot advance from current phase.':
|
||||
'이미 다음 단계로 넘어간 상태예요. 최신 상태로 맞췄어요.',
|
||||
'현재 단계에서는 다음 선수로 넘어갈 수 없어요. 현재 선수를 확인해 주세요.',
|
||||
'Auction roster validation failed.':
|
||||
'팀 배정 상태를 확인해야 해 경매를 완료하지 못했습니다.',
|
||||
'No bid to mark sold.': '낙찰할 입찰이 없어요. 최신 상태로 맞췄어요.',
|
||||
'Cannot pass a player with an active bid.':
|
||||
'진행 중인 입찰이 있어 유찰할 수 없어요.',
|
||||
|
||||
@@ -3,6 +3,7 @@ import { io, type Socket } from 'socket.io-client';
|
||||
import { API_BASE_URL, useAuthUserId } from '../config';
|
||||
import { acquireAccessToken } from '../lib/auth/token-provider';
|
||||
import type { ApiAuction, ApiAuctionChatMessage, Position } from './types';
|
||||
import { resolveAuctionActionRejection } from './auction-action-retry';
|
||||
import {
|
||||
isAuctionResyncRecommended,
|
||||
resolveAuctionErrorMessage,
|
||||
@@ -691,13 +692,21 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
clearPendingActionRequest(
|
||||
ack?.auctionActionRequestId ?? auctionActionRequestId,
|
||||
);
|
||||
// 2) 자동 재시도: "낡은 화면 때문에 거부"였고 동기 rebaseline 소스(state)가
|
||||
// 있을 때만 1회. assignedPosition 등 원래 payload는 유지하고 관측값/요청
|
||||
// id만 새로 만든다. 재시도 시에는 중간 에러 문구를 띄우지 않는다(무음 복구).
|
||||
const canAutoRetry =
|
||||
Boolean(ack.state) &&
|
||||
isAuctionResyncRecommended(ack) &&
|
||||
retryAttempt < 1;
|
||||
// 최신 화면과 거부 응답이 모두 원래 요청의 대상일 때만 한 번 재시도한다.
|
||||
const { applyServerState, retry: canAutoRetry } =
|
||||
resolveAuctionActionRejection({
|
||||
action: eventName,
|
||||
request: payload,
|
||||
serverState: ack.state,
|
||||
currentState: latestAuctionRef.current,
|
||||
resyncRecommended: isAuctionResyncRecommended(ack),
|
||||
retryAttempt,
|
||||
});
|
||||
if (ack.state && applyServerState) {
|
||||
commitAuctionState(ack.state, 'action-reject-rebaseline');
|
||||
} else if (!ack.state && isAuctionResyncRecommended(ack)) {
|
||||
resyncAuctionState();
|
||||
}
|
||||
// 거부 시 "클라가 보낸 관측 revision"과 "서버가 동봉한 진짜 state"를 함께
|
||||
// 기록한다. observedRevision < serverRevision 이면 stale-client CONFLICT 확정.
|
||||
addNewRelicPageAction('AuctionClientActionRejected', {
|
||||
@@ -725,18 +734,14 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
...describeAuctionForTelemetry('observed', latestAuctionRef.current),
|
||||
...describeAuctionForTelemetry('server', ack?.state ?? null),
|
||||
});
|
||||
// 1) rebaseline: 서버가 동봉한 최신 state를 즉시 반영(없으면 join으로 재요청).
|
||||
// commitAuctionState는 latestAuctionRef를 동기로 갱신하므로, 이후
|
||||
// buildAuctionActionPayload는 최신 관측값(revision/phase/선수)을 읽는다.
|
||||
if (ack.state) {
|
||||
commitAuctionState(ack.state, 'action-reject-rebaseline');
|
||||
} else if (isAuctionResyncRecommended(ack)) {
|
||||
resyncAuctionState();
|
||||
}
|
||||
if (canAutoRetry) {
|
||||
emitAuctionAction(
|
||||
eventName,
|
||||
{ ...payload, ...buildAuctionActionPayload() },
|
||||
{
|
||||
...payload,
|
||||
auctionActionRequestId: createClientRequestId(),
|
||||
clientObservedRevision: latestAuctionRef.current?.revision,
|
||||
},
|
||||
retryAttempt + 1,
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -2144,7 +2144,10 @@ export default function AuctionPage() {
|
||||
</Link>
|
||||
|
||||
{errorMessage && (
|
||||
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
|
||||
<div
|
||||
role="alert"
|
||||
className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500"
|
||||
>
|
||||
{errorMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user