일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- css framework
- spread 연산자
- express
- Spring Boot
- draganddrop
- MySQL
- java
- mongoDB
- screencapture
- Unity IAP
- docker
- Camera Movement
- nodejs
- SDK upgrade
- OverTheWire
- Git
- Unity Editor
- Google Refund
- unity
- server
- rpg server
- critical rendering path
- --watch
- Google Developer API
- Digital Ocean
- react
- Camera Zoom
- Packet Network
- linux
- springboot
- Today
- Total
우당탕탕 개발일지
[nestJs] 파일 다운로드 시 서버가 재실행되는 문제 (feat. --watch) 본문
파일을 입력받아 파싱 > 새로운 파일을 다운로드 할 수 있는 API를 제작했었다. 그런데 용량이 큰 파일을 처리하면 클라이언트 쪽에서 아래 에러와 함께 전송이 실패하는 문제가 발생했다.
ERR_CONTENT_LENGTH_MISMATCH 200 (OK)
문제는, 로컬에서 서버를 실행시키고 API를 요청했을 때는 동일한 파일이더라도 정상적으로 작동한다는 것이다.
pm2 와 nginx를 사용중이었기 때문에 세팅에 문제가 있을 것이라고 생각했다.
여러가지 옵션들을 건드리는데도 해결이 되지 않았으나, 서버 로그를 통해 단서를 찾을 수 있었다.
0|server | start send file. size:196358
0|server | Streaming file: /root/project/server/uploads/processFile25522.xlsx
0|server | Chunk sent: 65536 bytes , bytesSent:65536
0|server | Chunk sent: 65536 bytes , bytesSent:131072
0|server | Chunk sent: 65286 bytes , bytesSent:196358
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [NestFactory] Starting Nest application...
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [InstanceLoader] MulterModule dependencies initialized +25ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [InstanceLoader] AppModule dependencies initialized +3ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [InstanceLoader] FileModule dependencies initialized +0ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [RoutesResolver] AppController {/}: +9ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [RouterExplorer] Mapped {/, GET} route +6ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [RoutesResolver] FileController {/file}: +1ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [RouterExplorer] Mapped {/file/upload, POST} route +3ms
0|server | [Nest] 1807067 - 01/17/2025, 1:48:08 AM LOG [NestApplication] Nest application successfully started +5ms
Send Complete가 발생하지 않았는데 갑자기 서버가 재실행되기 시작한다. 정상적인 프로세스라면 아래처럼 total byte send.. 로그가 추가적으로 나왔어야했다. 멀쩡한 서버가 왜자꾸 재시작하는건가 미치기 일보직전에 엄청난 사실을 알았다.
0|server | start send file. size:65301
0|server | Streaming file: /root/project/server/uploads/processFile21486.xlsx
0|server | Chunk sent: 65301 bytes , bytesSent:65301
0|server | Total bytes sent: 65301
0|server | Download complete. Deleting file: /root/project/server/uploads/processFile21486.xlsx
0|server | Stream destroyed.
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [NestFactory] Starting Nest application...
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [InstanceLoader] MulterModule dependencies initialized +26ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [InstanceLoader] AppModule dependencies initialized +3ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [InstanceLoader] FileModule dependencies initialized +3ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [RoutesResolver] AppController {/}: +12ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [RouterExplorer] Mapped {/, GET} route +6ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [RoutesResolver] FileController {/file}: +2ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [RouterExplorer] Mapped {/file/upload, POST} route +6ms
0|server | [Nest] 1807628 - 01/17/2025, 2:09:28 AM LOG [NestApplication] Nest application successfully started +7ms
0|server | Server started
서버통신이 성공한 API요청도 서버가 재시작된다는 점이었다. 즉, 파일이 문제가 아니라, API 요청을 할 때마다 서버가 재시작하고 있었고, 용량이 큰 파일의 경우 전송중에 서버가 꺼져서 마저 전송을 받지 못하는것이다.
문제는 어이없는 곳에서 발생했다..
로컬환경에서 서버를 실행할떄 코드 수정시 바로 반영되게 하게끔 --watch 옵션을 활성화했고, 자연스럽게 배포할때도 이 옵션을 활성화해서 실행시켰다.
pm2 start dist/main.js --name "server" --watch
그런데 파싱한 파일을 서버에 저장하면 코드가 수정되었다고 판단되어 서버가 재시작되는것이었다..!!!!
서버컴퓨터에 파일저장 >> 클라이언트에 전송 >> 저장된 파일 삭제 인데,
서버컴퓨터에 파일저장 >> 클라이언트에 전.. >> 어? 너 코드바뀌었니?? 재시작!! >> FAIL..
내가만약 지금 목욕탕에 있었다면 유레카를 외치면서 밖으로 뛰어나갔을텐데..
그래서 --watch 옵션을 제거하고 재실행했더니 정상적으로 잘된다..ㅎ
2시간의 삽질이 유의미하게 끝나서 다행이다. 똑같은 실수는 다시는 안할것같다.
'Server' 카테고리의 다른 글
[SpringBoot] 민감한 데이터 .env 에 보관/사용하기 (0) | 2025.01.12 |
---|---|
[SpringBoot] 네이버 메일 전송하기 (0) | 2025.01.12 |
[SpringBoot] 7. 스프링부트 배포하기(완) (0) | 2025.01.10 |
[SpringBoot] 6. 데이터베이스의 객체와 연관관계 (Repository 계층) (1) | 2025.01.08 |
[SpringBoot] 5. 트랜잭션 (Service 계층) (0) | 2025.01.06 |