ERR_CONNECTION_RESET 문제 해결하기최근 프로젝트에서 드론 이미지 같은 대용량 ZIP 파일을 업로드하다가 브라우저에서 갑자기 ERR_CONNECTION_RESET 에러가 뜨는 상황이 발생했는데
처음엔 이유를 잘 몰라서 삽질을 좀 했는데, 정리해보니 해결 흐름이 명확하더라고요. 여기서 배운 내용을 기록합니다.
ERR_CONNECTION_RESET 발생처음에는 파일 이름이나 DTO 처리 문제인 줄 알았지만, 알고 보니 서버가 한 번에 처리할 수 있는 용량을 초과해서 연결을 끊는 것이 원인이었어요.
Multipart 설정 부족
maxUploadSize나 maxInMemorySize를 넘으면 서버가 연결을 끊음메모리 과부하
DB 처리 방식
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10737418240"/> <!-- 10GB -->
<property name="maxInMemorySize" value="20971520"/> <!-- 20MB -->
</bean>
try (ZipInputStream zis = new ZipInputStream(file.getInputStream())) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
File tempFile = new File(System.getProperty("java.io.tmpdir"), entry.getName());
Files.copy(zis, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
fileBatchList.add(tempFile);
}
}
}
public void saveBatch(List<File> files) throws SQLException {
Connection conn = dataSource.getConnection();
try {
conn.setAutoCommit(false);
String sql = "INSERT INTO images (filepath, filename, filesize) VALUES (?, ?, ?)";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
for (File file : files) {
pstmt.setString(1, file.getAbsolutePath());
pstmt.setString(2, file.getName());
pstmt.setLong(3, file.length());
pstmt.addBatch();
}
pstmt.executeBatch();
}
conn.commit();
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
}
간단하게 그림으로 표현하면 흐름은 이렇습니다.
클라이언트 → Spring Multipart → 임시 파일 저장 → 배치 수집 → 트랜잭션 시작 → DB 배치 Insert → Commit/롤백 → 완료
결론적으로, ERR_CONNECTION_RESET 에러는 서버가 한 번에 처리할 수 있는 용량과 시간 초과 때문에 발생하는 경우가 많습니다.
멀티파트 설정 조정, 스트리밍 처리, 배치 DB insert, 트랜잭션 관리 등 기능적 구조를 정리하면 자연스럽게 해결됩니다.