콘솔 출력이 불가능했기 때문에 Heroku 로그에는 기록조차 되지 않았고, uncaughtException 핸들러를 이용해 Slack으로 스택을 전송함
↓ Node 에러 스택
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:905:11)
at Socket._write (node:net:917:8)
at writeOrBuffer (node:internal/streams/writable:391:12)
at _write (node:internal/streams/writable:332:10)
at Socket.Writable.write (node:internal/streams/writable:336:10)
at console.value (node:internal/console/constructor:299:16)
at console.log (node:internal/console/constructor:376:26)
빈번한 재시작 (2022-11-04)
기본 재시작 주기는 1일이지만, 고작 10분 만에 SIGTERM 신호를 보내는 경우도 존재
↓ shell
$ heroku logs --app=xxx
2022-11-04T15:42:53.188721+00:00 heroku[web.1]: Cycling
2022-11-04T15:42:53.191834+00:00 heroku[web.1]: State changed from up to starting
2022-11-04T15:42:54.745019+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-04T15:42:54.935443+00:00 heroku[web.1]: Process exited with status 143
2022-11-04T15:43:04.647817+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-04T15:43:07.865400+00:00 app[web.1]: Express server listening on 26655
2022-11-04T15:43:08.358056+00:00 heroku[web.1]: State changed from starting to up
2022-11-05T15:59:52.193485+00:00 heroku[web.1]: Cycling
2022-11-05T15:59:52.199264+00:00 heroku[web.1]: State changed from up to starting
2022-11-05T15:59:52.827689+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-05T15:59:53.127857+00:00 heroku[web.1]: Process exited with status 143
2022-11-05T16:00:03.219442+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-05T16:00:05.914223+00:00 app[web.1]: Express server listening on 27518
2022-11-05T16:00:06.014664+00:00 heroku[web.1]: State changed from starting to up
2022-11-06T16:28:34.682573+00:00 heroku[web.1]: Cycling
2022-11-06T16:28:34.684590+00:00 heroku[web.1]: State changed from up to starting
2022-11-06T16:28:35.298049+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-06T16:28:35.536632+00:00 heroku[web.1]: Process exited with status 143
2022-11-06T16:28:46.543968+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-06T16:28:49.632588+00:00 app[web.1]: Express server listening on 46591
2022-11-06T16:28:50.176669+00:00 heroku[web.1]: State changed from starting to up
2022-11-07T17:03:23.014423+00:00 heroku[web.1]: Cycling
2022-11-07T17:03:23.018550+00:00 heroku[web.1]: State changed from up to starting
2022-11-07T17:03:23.773273+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-07T17:03:23.997377+00:00 heroku[web.1]: Process exited with status 143
2022-11-07T17:03:35.633367+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-07T17:03:38.101356+00:00 app[web.1]: Express server listening on 12207
2022-11-07T17:03:38.542343+00:00 heroku[web.1]: State changed from starting to up
2022-11-08T17:44:34.257748+00:00 heroku[web.1]: Cycling
2022-11-08T17:44:34.260294+00:00 heroku[web.1]: State changed from up to starting
2022-11-08T17:44:34.961998+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-08T17:44:35.349123+00:00 heroku[web.1]: Process exited with status 143
2022-11-08T17:44:44.719748+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-08T17:44:47.333908+00:00 app[web.1]: Express server listening on 14749
2022-11-08T17:44:47.536761+00:00 heroku[web.1]: State changed from starting to up
2022-11-09T18:05:53.566487+00:00 heroku[web.1]: Cycling
2022-11-09T18:05:53.569847+00:00 heroku[web.1]: State changed from up to starting
2022-11-09T18:05:54.158427+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-09T18:05:54.634928+00:00 heroku[web.1]: Process exited with status 143
2022-11-09T18:06:03.068936+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-09T18:06:05.511106+00:00 app[web.1]: Express server listening on 28627
2022-11-09T18:06:05.944568+00:00 heroku[web.1]: State changed from starting to up
2022-11-09T20:45:53.115643+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-09T20:45:53.542677+00:00 heroku[web.1]: Process exited with status 143
2022-11-09T20:46:57.112428+00:00 heroku[web.1]: State changed from up to down
2022-11-09T20:46:57.114989+00:00 heroku[web.1]: State changed from down to starting
2022-11-09T20:47:08.875162+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-09T20:47:13.184638+00:00 app[web.1]: Express server listening on 52035
2022-11-09T20:48:42.474102+00:00 heroku[web.1]: State changed from starting to up
2022-11-09T20:56:48.120912+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-11-09T20:56:50.546725+00:00 heroku[web.1]: Process exited with status 143
2022-11-09T20:57:19.805546+00:00 heroku[web.1]: State changed from up to down
2022-11-09T20:57:19.807460+00:00 heroku[web.1]: State changed from down to starting
2022-11-09T20:57:34.022542+00:00 heroku[web.1]: Starting process with command `node app`
2022-11-09T20:57:41.713346+00:00 app[web.1]: Express server listening on 25985
2022-11-09T20:57:45.249367+00:00 heroku[web.1]: State changed from starting to up
copytruncate 옵션은 편리하지만, copy 후 truncate 하는 사이에 기록된 로그는 유실될 수 있다 -- copy가 오래 걸릴수록 유실되는 크기도 커진다
Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost
따라서 copytruncate 옵션이 적합하지 않은 경우, 프로세스에 시그널을 보내 새로운 파일(이름이 이전과 동일하든 그렇지 않든)에 로그를 기록하도록 지시하는 것이 좋다
↓ Nginx 예.
postrotate
if [ -f /.../nginx.pid ]; then
kill -USR1 $(cat /.../nginx.pid)
fi
endscript
서버 응답이 잘려서 올 때
Linux > docker-machine > container(서버) 환경에서, Linux 서버의 용량이 부족할 때 이하의 현상이 발생함을 확인
container, docker-machine에서 서버 응답은 정상 획득
Linux 서버 및 그 밖에서는 서버 응답이 잘림
암호화 오류. Padding is invalid and cannot be removed
스트림을 직접 이용하는 경우, flush 완료됐는지 확인이 필요하다
↓ C# 암호화
var source = File.ReadAllBytes("source_file");
using var aes = Aes.Create();
aes.Key = Encoding.ASCII.GetBytes("32 Bytes String");
aes.IV = Encoding.ASCII.GetBytes("16 Bytes String");
using var mStream = new MemoryStream();
{
using var cStream = new CryptoStream(mStream, aes.CreateEncryptor(), CryptoStreamMode.Write);
cStream.Write(source, 0, source.Length);
} // 블록을 추가하여 암호화 스트림이 먼저 flush + close하도록 보장
var target = mStream.ToArray();
↓ C# 복호화
{
var source = File.ReadAllBytes("source_file");
var aes = Aes.Create();
aes.Key = Encoding.ASCII.GetBytes("32 Bytes String");
aes.IV = Encoding.ASCII.GetBytes("16 Bytes String");
using var mStream = new MemoryStream(source);
using var cStream = new CryptoStream(mStream, aes.CreateDecryptor(), CryptoStreamMode.Read);
using var fStream = new FileStream("target_file", FileMode.Create);
var buf = new byte[source.Length];
var length = cStream.Read(buf, 0, buf.Length);
fStream.Write(buf, 0, length);
} // 블록을 추가하여 모든 스트림이 알아서 닫히도록 구성