@yolo-croket-dev/core 1.7.44-slowquery.6 → 1.7.44-slowquery.8

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.
@@ -8,7 +8,6 @@ interface RequestContext {
8
8
  export declare class AbortContext {
9
9
  private static asyncLocalStorage;
10
10
  private static contextCounter;
11
- private static pendingAbortCallbacks;
12
11
  static run<T>(abortSignal: AbortSignal, requestId: string, callback: (context: RequestContext) => T): T;
13
12
  static getCurrentAbortSignal(): AbortSignal | null;
14
13
  static getCurrentRequestId(): string | null;
@@ -16,16 +15,7 @@ export declare class AbortContext {
16
15
  abortSignal: AbortSignal;
17
16
  requestId: string;
18
17
  } | null;
19
- /**
20
- * 컨텍스트 종료 전에 모든 abort 이벤트 리스너가 완료될 때까지 대기
21
- */
22
- static waitForAbortHandlers(requestId: string): Promise<void>;
23
- /**
24
- * 이 컨텍스트의 모든 abort 이벤트 처리 완료 후 disable 호출
25
- */
26
- static disableAfterAbortHandlers(requestId: string): Promise<void>;
27
18
  static disable(): void;
28
- static disableDeferred(): void;
29
19
  static endContext(context?: RequestContext): void;
30
20
  static updateContext(updatedData: Partial<RequestContext>): void;
31
21
  /**
@@ -12,35 +12,6 @@ class AbortContext {
12
12
  createdAt: Date.now(),
13
13
  parentContext: currentContext || undefined,
14
14
  };
15
- // abort 이벤트가 발생할 때까지 대기하는 Promise 생성
16
- const abortPromise = new Promise((resolve) => {
17
- const checkAbortStatus = () => {
18
- if (abortSignal.aborted) {
19
- // 이벤트 루프를 두 번 통과시켜서 모든 abort 리스너가 완료되도록 보장
20
- setTimeout(() => {
21
- setTimeout(() => {
22
- resolve();
23
- }, 0);
24
- }, 0);
25
- }
26
- else {
27
- // 아직 abort가 발생하지 않았으면 즉시 resolve
28
- resolve();
29
- }
30
- };
31
- abortSignal.addEventListener('abort', checkAbortStatus, { once: true });
32
- // abort 이벤트가 이미 발생했는지 확인
33
- if (abortSignal.aborted) {
34
- checkAbortStatus();
35
- }
36
- else {
37
- // abort가 발생하지 않은 상태라면 즉시 resolve
38
- setTimeout(() => {
39
- resolve();
40
- }, 0);
41
- }
42
- });
43
- this.pendingAbortCallbacks.set(newContext.requestId, abortPromise);
44
15
  return this.asyncLocalStorage.run(newContext, callback.bind(this, newContext));
45
16
  }
46
17
  static getCurrentAbortSignal() {
@@ -61,31 +32,9 @@ class AbortContext {
61
32
  }
62
33
  return null;
63
34
  }
64
- /**
65
- * 컨텍스트 종료 전에 모든 abort 이벤트 리스너가 완료될 때까지 대기
66
- */
67
- static async waitForAbortHandlers(requestId) {
68
- const promise = this.pendingAbortCallbacks.get(requestId);
69
- if (promise) {
70
- await promise;
71
- this.pendingAbortCallbacks.delete(requestId);
72
- }
73
- }
74
- /**
75
- * 이 컨텍스트의 모든 abort 이벤트 처리 완료 후 disable 호출
76
- */
77
- static async disableAfterAbortHandlers(requestId) {
78
- await this.waitForAbortHandlers(requestId);
79
- this.asyncLocalStorage.disable();
80
- }
81
35
  static disable() {
82
36
  this.asyncLocalStorage.disable();
83
37
  }
84
- static disableDeferred() {
85
- setTimeout(() => {
86
- this.asyncLocalStorage.disable();
87
- }, 0);
88
- }
89
38
  // 컨텍스트 종료
90
39
  // eslint-disable-next-line consistent-return
91
40
  static endContext(context) {
@@ -140,5 +89,3 @@ class AbortContext {
140
89
  exports.AbortContext = AbortContext;
141
90
  AbortContext.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
142
91
  AbortContext.contextCounter = 0;
143
- // abort 이벤트 처리를 추적하기 위한 Map
144
- AbortContext.pendingAbortCallbacks = new Map();
@@ -1,23 +1,7 @@
1
1
  export declare class ContextPromisePatch {
2
2
  private static isPatched;
3
3
  private static originalPromise;
4
- private static originalSetTimeout;
5
- private static originalSetInterval;
6
- private static originalClearTimeout;
7
- private static originalClearInterval;
8
- private static contextTimers;
9
- private static timerContextMap;
10
- private static contextPromises;
11
- /**
12
- * 특정 컨텍스트의 모든 타이머 정리
13
- */
14
- static clearContextTimers(contextId: string): void;
15
- /**
16
- * 특정 컨텍스트의 모든 Promise가 완료될 때까지 대기
17
- */
18
- static waitForContextPromises(contextId: string): Promise<void>;
19
4
  static patch(): void;
20
5
  private static patchPromise;
21
- private static patchTimeouts;
22
6
  static unpatch(): void;
23
7
  }
@@ -3,41 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContextPromisePatch = void 0;
4
4
  const abort_context_1 = require("./abort-context");
5
5
  class ContextPromisePatch {
6
- /**
7
- * 특정 컨텍스트의 모든 타이머 정리
8
- */
9
- static clearContextTimers(contextId) {
10
- const timers = this.contextTimers.get(contextId);
11
- if (timers) {
12
- for (const timerId of timers) {
13
- this.originalClearTimeout(timerId);
14
- this.originalClearInterval(timerId);
15
- this.timerContextMap.delete(timerId);
16
- }
17
- this.contextTimers.delete(contextId);
18
- }
19
- }
20
- /**
21
- * 특정 컨텍스트의 모든 Promise가 완료될 때까지 대기
22
- */
23
- static async waitForContextPromises(contextId) {
24
- const promises = this.contextPromises.get(contextId);
25
- if (promises && promises.size > 0) {
26
- // 모든 Promise가 완료될 때까지 기다림
27
- await Promise.allSettled(Array.from(promises));
28
- }
29
- }
30
6
  static patch() {
31
7
  if (this.isPatched) {
32
8
  return;
33
9
  }
34
10
  this.originalPromise = global.Promise;
35
- this.originalSetTimeout = global.setTimeout;
36
- this.originalSetInterval = global.setInterval;
37
- this.originalClearTimeout = global.clearTimeout;
38
- this.originalClearInterval = global.clearInterval;
39
11
  this.patchPromise();
40
- this.patchTimeouts();
41
12
  this.isPatched = true;
42
13
  }
43
14
  static patchPromise() {
@@ -57,45 +28,8 @@ class ContextPromisePatch {
57
28
  return Promise.reject(new Error(`REQUEST_ABORTED: Promise가 중단되었습니다 (${contextId})`));
58
29
  }
59
30
  const promise = Reflect.construct(target, args);
60
- // abort 이벤트 리스너 추가하여 Promise를 즉시 reject
61
- const wrappedPromise = new Promise((resolve, reject) => {
62
- const checkAbort = () => {
63
- if (abortSignal.aborted) {
64
- reject(new Error(`REQUEST_ABORTED: Promise가 중단되었습니다 (${contextId})`));
65
- }
66
- };
67
- // abort 이벤트 리스너 등록
68
- abortSignal.addEventListener('abort', checkAbort);
69
- // 원본 promise가 완료될 때까지 기다림
70
- promise
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- .then((result) => {
73
- abortSignal.removeEventListener('abort', checkAbort);
74
- resolve(result);
75
- })
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
- .catch((error) => {
78
- abortSignal.removeEventListener('abort', checkAbort);
79
- reject(error);
80
- });
81
- // 이미 abort된 경우
82
- if (abortSignal.aborted) {
83
- abortSignal.removeEventListener('abort', checkAbort);
84
- reject(new Error(`REQUEST_ABORTED: Promise가 중단되었습니다 (${contextId})`));
85
- }
86
- });
87
- // Promise 추적 추가
88
- if (!ContextPromisePatch.contextPromises.has(contextId)) {
89
- ContextPromisePatch.contextPromises.set(contextId, new Set());
90
- }
91
- ContextPromisePatch.contextPromises.get(contextId).add(wrappedPromise);
92
- // Promise 완료 시 추적에서 제거
93
- wrappedPromise.finally(() => {
94
- var _a;
95
- (_a = ContextPromisePatch.contextPromises.get(contextId)) === null || _a === void 0 ? void 0 : _a.delete(wrappedPromise);
96
- });
97
31
  // Promise 체인에 자동으로 중단 확인 추가
98
- return wrappedPromise.then((result) => {
32
+ return promise.then((result) => {
99
33
  // 컨텍스트가 여전히 유효한지 확인
100
34
  const currentContextCheck = abort_context_1.AbortContext.getCurrentContext();
101
35
  if (!currentContextCheck || currentContextCheck.requestId !== contextId) {
@@ -169,173 +103,13 @@ class ContextPromisePatch {
169
103
  return originalReject.call(global.Promise, reason);
170
104
  };
171
105
  }
172
- static patchTimeouts() {
173
- // 각 컨텍스트별로 활성 타이머를 추적
174
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
- const activeTimers = new Map();
176
- // setTimeout 패치
177
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
178
- global.setTimeout = (handler, timeout,
179
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
- ...args
181
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
- ) => {
183
- const currentContext = abort_context_1.AbortContext.getCurrentContext();
184
- if (!currentContext) {
185
- // 원본 함수에 args 전달 (타입 안전하게)
186
- if (args.length > 0) {
187
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
188
- return this.originalSetTimeout(handler, timeout, ...args);
189
- }
190
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
191
- return this.originalSetTimeout(handler, timeout);
192
- }
193
- const abortSignal = currentContext.abortSignal;
194
- const contextId = currentContext.requestId;
195
- if (abortSignal.aborted) {
196
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
197
- throw new Error(`REQUEST_ABORTED: setTimeout이 중단되었습니다 (${contextId})`);
198
- }
199
- const originalHandler = typeof handler === 'function' ? handler : undefined;
200
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
201
- const wrappedHandler = () => {
202
- // 타이머 실행 시점에 abort 여부 확인
203
- if (abortSignal.aborted) {
204
- return;
205
- }
206
- if (originalHandler) {
207
- originalHandler();
208
- }
209
- };
210
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
211
- const timeoutId = this.originalSetTimeout(wrappedHandler, timeout);
212
- activeTimers.set(timeoutId, {
213
- contextId,
214
- abortSignal,
215
- });
216
- // 타이머 추적
217
- if (!this.contextTimers.has(contextId)) {
218
- this.contextTimers.set(contextId, new Set());
219
- }
220
- this.contextTimers.get(contextId).add(timeoutId);
221
- this.timerContextMap.set(timeoutId, contextId);
222
- // 클로저로 필요한 정보를 캡처 (컨텍스트가 disable되어도 동작)
223
- const capturedContextId = contextId;
224
- const capturedActiveTimers = activeTimers;
225
- const onAbort = () => {
226
- var _a;
227
- this.originalClearTimeout(timeoutId);
228
- capturedActiveTimers.delete(timeoutId);
229
- (_a = this.contextTimers.get(capturedContextId)) === null || _a === void 0 ? void 0 : _a.delete(timeoutId);
230
- this.timerContextMap.delete(timeoutId);
231
- };
232
- abortSignal.addEventListener('abort', onAbort, { once: true });
233
- return timeoutId;
234
- };
235
- // setInterval 패치
236
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
- global.setInterval = (handler, timeout,
238
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
239
- ...args
240
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
241
- ) => {
242
- const currentContext = abort_context_1.AbortContext.getCurrentContext();
243
- if (!currentContext) {
244
- // 원본 함수에 args 전달 (타입 안전하게)
245
- if (args.length > 0) {
246
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
- return this.originalSetInterval(handler, timeout, ...args);
248
- }
249
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
- return this.originalSetInterval(handler, timeout);
251
- }
252
- const abortSignal = currentContext.abortSignal;
253
- const contextId = currentContext.requestId;
254
- if (abortSignal.aborted) {
255
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
256
- throw new Error(`REQUEST_ABORTED: setInterval이 중단되었습니다 (${contextId})`);
257
- }
258
- const originalHandler = typeof handler === 'function' ? handler : undefined;
259
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
260
- const wrappedHandler = () => {
261
- // 타이머 실행 시점에 abort 여부 확인
262
- if (abortSignal.aborted) {
263
- return;
264
- }
265
- if (originalHandler) {
266
- originalHandler();
267
- }
268
- };
269
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
270
- const intervalId = this.originalSetInterval(wrappedHandler, timeout);
271
- activeTimers.set(intervalId, {
272
- contextId,
273
- abortSignal,
274
- });
275
- // 타이머 추적
276
- if (!this.contextTimers.has(contextId)) {
277
- this.contextTimers.set(contextId, new Set());
278
- }
279
- this.contextTimers.get(contextId).add(intervalId);
280
- this.timerContextMap.set(intervalId, contextId);
281
- // 클로저로 필요한 정보를 캡처 (컨텍스트가 disable되어도 동작)
282
- const capturedContextId = contextId;
283
- const capturedActiveTimers = activeTimers;
284
- const onAbort = () => {
285
- var _a;
286
- this.originalClearInterval(intervalId);
287
- capturedActiveTimers.delete(intervalId);
288
- (_a = this.contextTimers.get(capturedContextId)) === null || _a === void 0 ? void 0 : _a.delete(intervalId);
289
- this.timerContextMap.delete(intervalId);
290
- };
291
- abortSignal.addEventListener('abort', onAbort, { once: true });
292
- return intervalId;
293
- };
294
- // clearTimeout 패치
295
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
296
- global.clearTimeout = (timerId) => {
297
- var _a;
298
- activeTimers.delete(timerId);
299
- const contextId = this.timerContextMap.get(timerId);
300
- if (contextId) {
301
- (_a = this.contextTimers.get(contextId)) === null || _a === void 0 ? void 0 : _a.delete(timerId);
302
- this.timerContextMap.delete(timerId);
303
- }
304
- this.originalClearTimeout(timerId);
305
- };
306
- // clearInterval 패치
307
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
- global.clearInterval = (timerId) => {
309
- var _a;
310
- activeTimers.delete(timerId);
311
- const contextId = this.timerContextMap.get(timerId);
312
- if (contextId) {
313
- (_a = this.contextTimers.get(contextId)) === null || _a === void 0 ? void 0 : _a.delete(timerId);
314
- this.timerContextMap.delete(timerId);
315
- }
316
- this.originalClearInterval(timerId);
317
- };
318
- }
319
106
  static unpatch() {
320
107
  if (!this.isPatched) {
321
108
  return;
322
109
  }
323
110
  global.Promise = this.originalPromise;
324
- global.setTimeout = this.originalSetTimeout;
325
- global.setInterval = this.originalSetInterval;
326
- global.clearTimeout = this.originalClearTimeout;
327
- global.clearInterval = this.originalClearInterval;
328
111
  this.isPatched = false;
329
112
  }
330
113
  }
331
114
  exports.ContextPromisePatch = ContextPromisePatch;
332
115
  ContextPromisePatch.isPatched = false;
333
- // 컨텍스트별 활성 타이머 추적 (contextId -> Set<timerId>)
334
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
335
- ContextPromisePatch.contextTimers = new Map();
336
- // timerId -> contextId 매핑
337
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
338
- ContextPromisePatch.timerContextMap = new Map();
339
- // 컨텍스트별 활성 Promise 추적
340
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
341
- ContextPromisePatch.contextPromises = new Map();
@@ -57,7 +57,6 @@ let RPCInterceptor = class RPCInterceptor {
57
57
  this.gracefulShutdownService = gracefulShutdownService;
58
58
  this.DEFAULT_TIMEOUT = 1000 * 60 * 29; // 29분 타임아웃
59
59
  this.DEFAULT_TIMEOUT_MESSAGE = '요청이 타임아웃되었습니다.';
60
- context_promise_patch_1.ContextPromisePatch.patch();
61
60
  }
62
61
  maxLengthOverShorten(data) {
63
62
  if (typeof data !== 'string') {
@@ -170,6 +169,7 @@ let RPCInterceptor = class RPCInterceptor {
170
169
  correlationId,
171
170
  isMessageAck: false,
172
171
  };
172
+ context_promise_patch_1.ContextPromisePatch.patch();
173
173
  let abortController = new AbortController();
174
174
  /** consume 메시지 전부 cancel */
175
175
  if (this.gracefulShutdownService.isApplicationExit) {
@@ -355,14 +355,12 @@ let RPCInterceptor = class RPCInterceptor {
355
355
  }
356
356
  },
357
357
  error: localErrorProcessor,
358
- }), (0, operators_1.finalize)(async () => {
358
+ }), (0, operators_1.finalize)(() => {
359
359
  this.gracefulShutdownService.popActiveInterceptors(execInterceptor);
360
- // 활성 타이머를 모두 정리
361
- context_promise_patch_1.ContextPromisePatch.clearContextTimers(execInterceptor.traceId);
360
+ setTimeout(() => {
361
+ functions_1.AbortContext.disable();
362
+ }, 1000 * 10);
362
363
  abortController = null;
363
- // 모든 Promise가 완료될 때까지 기다림
364
- await context_promise_patch_1.ContextPromisePatch.waitForContextPromises(execInterceptor.traceId);
365
- functions_1.AbortContext.disable();
366
364
  return rxjs_1.EMPTY;
367
365
  })));
368
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-croket-dev/core",
3
- "version": "1.7.44-slowquery.6",
3
+ "version": "1.7.44-slowquery.8",
4
4
  "author": "Yolo Co., Ltd.",
5
5
  "description": "Yolo commonization module",
6
6
  "main": "index.js",