기본값부터 말하면 5분입니다. 300초가 넘는 요청은 끊깁니다. 늘려야 한다면 최대 60분, 3600초까지 올릴 수 있습니다.
이 정도는 외워 둘 만합니다. 그런데 공식 문서를 읽어 보니 숫자보다 더 챙길 것이 있었습니다.
설정하는 곳
방법은 세 가지입니다.
- gcloud:
gcloud run services update 서비스이름 --timeout=값. 숫자는 초로 읽히고, 1m20s 같은 기간 표기도 됩니다.
- 콘솔: 서비스의
Scaling 탭에서 Request timeout에 1~3600 사이 값을 초 단위로 넣고 배포합니다.
- YAML:
spec.template.spec 아래 timeoutSeconds에 값을 적고 gcloud run services replace로 올립니다.
타임아웃을 바꾸면 새 리비전이 만들어집니다. 이후 리비전은 따로 바꾸지 않는 한 같은 값을 이어받습니다.
시간이 지나면
Cloud Run이 연결을 닫고 504를 돌려줍니다. 호출한 쪽에서는 요청이 실패한 것으로 보입니다.
여기서 하나 조심할 점이 있습니다. 문서에 따르면 연결을 닫아도 컨테이너 인스턴스가 멈추는 것은 아닙니다. 끊긴 요청을 서버가 계속 처리하고 있을 수 있습니다.
그러니 타임아웃이 난 요청은 실패가 아니라 "결과를 모르는 상태"로 보는 편이 안전합니다. 같은 요청을 다시 보내도 문제가 없게 만들어 두는 이유입니다. 이런 상황을 실제로 겪은 이야기는 배치 파이프라인 글에 적어 두었습니다.
덧붙이는 메모
이 블로그의 검색 답변에 같은 질문을 던졌더니 기본값이 60초라고 답했습니다. 공식 문서의 300초와 달랐습니다. 모델이 일반 지식으로 답하면 수치가 틀릴 수 있다는 것을 직접 본 사례입니다.
그래서 이 글의 숫자는 모두 위 문서에서 직접 읽은 값입니다. 문서가 바뀔 수 있으니 중요한 곳에 쓰기 전에는 한 번 더 확인해 주세요.
To start with the default, it is 5 minutes. Requests exceeding 300 seconds are cut off. If you need to increase it, you can raise it up to a maximum of 60 minutes, 3600 seconds.
This much is worth memorizing. However, after reading the official documentation, there were things to keep in mind beyond just the numbers.
There are three methods.
- gcloud:
gcloud run services update 서비스이름 --timeout=값. Numbers are read as seconds, and duration notations like 1m20s are also possible.
- Console: In the service's
Scaling tab, enter a value between 1 and 3600 in seconds for Request timeout and deploy.
- YAML: Write the value in
timeoutSeconds under spec.template.spec and apply it with gcloud run services replace.
Changing the timeout creates a new revision. Subsequent revisions inherit the same value unless changed separately.
When time runs out
Cloud Run closes the connection and returns 504. To the caller, the request appears to have failed.
There is one point to be careful about here. According to the documentation, closing the connection does not stop the container instance. The server may still be processing the cut-off request.
Therefore, it is safer to view a timed-out request not as a failure but as a "state where the result is unknown." This is why you should set things up so that resending the same request causes no problem. I have written about a real experience of this situation in the batch pipeline post.
Additional note
When I asked the same question to this blog's search answer, it replied that the default is 60 seconds. This differed from the official documentation's 300 seconds. This is a case where I directly saw that if a model answers with general knowledge, the figures can be wrong.
So the numbers in this post are all values read directly from the document above. Since the documentation can change, please verify once more before using them in important places.