@yolo-croket-dev/core 1.7.25-slowquery.0 → 1.7.25-slowquery.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -179,7 +179,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
179
179
|
const arg = args[0];
|
|
180
180
|
const rmq = args[1];
|
|
181
181
|
// 메시지에서 AbortController 가져오기
|
|
182
|
-
const abortController = rmq.abortController;
|
|
182
|
+
const abortController = rmq.args[0].abortController;
|
|
183
183
|
// const messageId = (rmq as any).messageId;
|
|
184
184
|
// if (!abortController) {
|
|
185
185
|
// // AbortController가 없으면 기본 처리
|
|
@@ -391,7 +391,8 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
391
391
|
// timeout 에러 처리
|
|
392
392
|
const isTimeoutError = err instanceof Error && err.name === 'TimeoutError';
|
|
393
393
|
if (isTimeoutError) {
|
|
394
|
-
if (abortController
|
|
394
|
+
if (abortController) {
|
|
395
|
+
abortController.abort();
|
|
395
396
|
throw new Error('Message aborted due to timeout');
|
|
396
397
|
}
|
|
397
398
|
msaLogger.error('[타임 아웃] 메시지 재전송 처리', { traceId: execInterceptor.traceId }, {
|
|
@@ -48,6 +48,7 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
48
48
|
this.messageAbortControllers.set(messageId, abortController);
|
|
49
49
|
// 타임아웃 설정
|
|
50
50
|
const timeoutId = setTimeout(() => {
|
|
51
|
+
console.log(`Message timeout: ${messageId}`);
|
|
51
52
|
abortController.abort();
|
|
52
53
|
this.cleanupMessage(messageId);
|
|
53
54
|
}, RMQ_DEFAULT_MESSAGE_TIMEOUT_MS);
|
|
@@ -57,9 +58,40 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
57
58
|
// AbortController를 메시지에 추가
|
|
58
59
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
|
59
60
|
message.abortController = abortController;
|
|
60
|
-
// eslint-disable-next-line no-param-reassign
|
|
61
|
+
// eslint-disable-next-line no-param-reassign
|
|
61
62
|
message.messageId = messageId;
|
|
62
|
-
|
|
63
|
+
// abort 상태 확인
|
|
64
|
+
if (abortController.signal.aborted) {
|
|
65
|
+
console.log(`Message already aborted: ${messageId}`);
|
|
66
|
+
this.cleanupMessage(messageId);
|
|
67
|
+
this.runningMessages -= 1;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Promise.race를 사용하여 abort와 handleMessage 경쟁
|
|
71
|
+
const handleMessagePromise = super.handleMessage(message, channel);
|
|
72
|
+
const abortPromise = new Promise((_, reject) => {
|
|
73
|
+
// 1초마다 abort 상태를 확인
|
|
74
|
+
const interval = setInterval(() => {
|
|
75
|
+
if (abortController.signal.aborted) {
|
|
76
|
+
reject(new Error(`Message aborted: ${messageId}`));
|
|
77
|
+
clearInterval(interval);
|
|
78
|
+
}
|
|
79
|
+
}, 1000);
|
|
80
|
+
});
|
|
81
|
+
// 둘 중 하나가 먼저 완료되면 그 결과를 반환
|
|
82
|
+
await Promise.race([
|
|
83
|
+
handleMessagePromise,
|
|
84
|
+
abortPromise,
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error.message.includes('Message aborted')) {
|
|
89
|
+
console.log(`Message processing aborted: ${messageId}`);
|
|
90
|
+
// abort로 인한 에러는 정상적으로 처리된 것으로 간주
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
63
95
|
}
|
|
64
96
|
finally {
|
|
65
97
|
this.cleanupMessage(messageId);
|