Skip to content

Commit 26d27fd

Browse files
committed
modify: redis cache JSON.parse 이슈 세부 처리와 예상치 못한 오류에 대한 grace-full exit
1 parent 5c51bdf commit 26d27fd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ process.on('SIGINT', () => gracefulShutdown('SIGINT'));
3434
// 예상치 못한 에러 처리
3535
process.on('uncaughtException', (error) => {
3636
logger.error('Uncaught Exception:', error);
37-
process.exit(1);
37+
gracefulShutdown('UNCAUGHT_EXCEPTION');
3838
});
3939

4040
process.on('unhandledRejection', (reason, promise) => {
4141
logger.error('Unhandled Rejection at:', promise, 'reason:', reason);
42-
process.exit(1);
42+
gracefulShutdown('UNCAUGHT_EXCEPTION');
4343
});

src/modules/cache/redis.cache.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,18 @@ export class RedisCache implements ICache {
9696
}
9797

9898
const value = await this.client.get(this.getFullKey(key));
99-
return value ? JSON.parse(value) : null;
99+
if (!value) return null;
100+
101+
// JSON.parse가 실패할 경우를 명시적으로 처리
102+
try {
103+
return JSON.parse(value);
104+
} catch (parseError) {
105+
logger.error(`Failed to parse cached value for key ${key}:`, parseError);
106+
// 손상된 캐시 데이터 삭제
107+
await this.delete(key);
108+
return null;
109+
}
110+
100111
} catch (error) {
101112
logger.error(`Cache GET error for key ${key}:`, error);
102113
return null;

0 commit comments

Comments
 (0)