Server-Sent Events(SSE) 연결이 끊어질 때마다 자동으로 재연결을 시도하는 로직으로 인해 다음과 같은 문제가 발생했습니다:
typescript
Copy
const connectSSE = (userId: string) => {
let retryCount = 0;
const MAX_RETRIES = 3;
let retryTimeout: NodeJS.Timeout;
// 재연결 시도 로직// 복잡한 재시도 메커니즘
}
typescript
Copy
const connectSSE = (userId: string) => {
const { setEventSource } = useSSEStore.getState();
try {
const eventSource = new EventSource(url, {
withCredentials: true,
});
// 단순화된 에러 처리
eventSource.onerror = (error) => {
if (eventSource.readyState === EventSource.CLOSED) {
eventSource.close();
setEventSource(null);
toast.error('실시간 알림 연결이 끊어졌습니다');
}
};
return eventSource;
} catch (error) {
console.error('SSE 초기화 실패:', error);
return null;
}
}