Received an UnknownHostException when attempting to interact with a service. See cause for the exact endpoint that is failing to resolve. If this is happening on an endpoint that previously worked, there may be a network connectivity issue or your DNS cache could be storing endpoints for too long.
Oct 30 01:22:14 ubuntu dockerd[2293083]: time="2024-10-30T01:22:14.752476083Z" level=error msg="[resolver] failed to query external DNS server" client-addr="udp:127.0.0.1:59546" dns-server="udp:127.0.0.53:53" error="read udp 127.0.0.1:59546->127.0.0.53:53: i/o
timeout" question=";sqs.ap-northeast-2.amazonaws.com.\tIN\t A" spanID=0e95ec0f4aa8fcbc traceID=c69346a57036fa48d3850134bb60b134
Oct 30 01:24:37 ubuntu newrelic-infra-service[3023646]: time="2024-10-30T01:24:37Z" level=warning msg="[engine] failed to flush chunk '3024031-1730251471.397479652.flb', retry in 9 seconds: task_id=0, input=tail.9 > output=newrelic.0 (out_id=0)" component=inte
grations.Supervisor output=stderr process=log-forwarder
์ ์ค๋ฅ๋ AWS SDK Java ์ SQS ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ ๋ฑ๋ก๋ ๋ฉ์์ง๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด์ HTTP ํต์ ์ ์ํํ ๋ ๋ฐ์ํ ์ ์๋ ์์ธ ์ํฉ์ ๋๋ค. ๊ฐ๋ฐ์๊ฐ ์์์ผํ DNS์ ๊ฐ์ด ๊ฐ๋ฐ์๊ฐ DNS์ ๋ํ ๊ฐ๋ ์ ์๊ณ ์์ด๋ ์์ ๊ฐ์ ์ํฉ์ ๋ํด ์์ธ์ ์ฐพ๊ณ ๋น ๋ฅด๊ฒ ๋์ฒํ ์ ์์๊น์? ๊ทธ๋ฆฌ๊ณ ์ด ๋คํธ์ํฌ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ด์ ๋ ๋ฌด์์ผ๊น์.
/etc/resolv.conf โ
์ฐ์ ๋ฆฌ๋ ์ค์์๋ NetworkManager๋ฅผ ํตํด /etc/resolv.conf ํตํด ๋ก์ปฌ DNS์ ์ธ๋ถ DNS์ ๋ํ ์ ๋ณด๋ฅผ ๊ด๋ฆฌํฉ๋๋ค. ํด๋น ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ฌ๋ด ์ปดํจํฐ์๋ ๋ผ์ฐํฐ์ ๋ํ ์์ดํผ์ Cloudflare(1.1.1.1)์ด DNS ์๋ฒ๋ก ์ง์ ๋์ด ์์์ต๋๋ค.
JVM์ DNS ์บ์ฑ ๊ธฐ๋ณธ๊ฐ์ 30์ด โ
The Java virtual machine (JVM) caches DNS name lookups. When the JVM resolves a hostname to an IP address, it caches the IP address for a specified period of time, known as the time-to-live (TTL). Because AWS resources use DNS name entries that occasionally change, we recommend that you configure your JVM with a TTL value of 5 seconds.
AWS SDK Java ์์๋ InetAddress.getAllByName๋ฅผ ์ฌ์ฉํ๋ฉฐ ์ด๋ก ์ธํด JVM์ DNS TTL ์ค์ ์ ์์กดํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ค์์ Amazon Corretto 17์ java.security ํ์ผ์ ๊ธฐ์ฌ๋ ์ฃผ์ ์ค๋ช ์ ๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก, ๊ธฐ๋ณธ์ ์ผ๋ก๋ (Security Manager๋ฅผ ์ค์ ํ์ง ์๊ธฐ ๋๋ฌธ์) 30์ด ๋์ DNS ๊ฒฐ๊ณผ๋ฅผ ์บ์ฑํ๊ฒ ๋ฉ๋๋ค.
#
# The Java-level namelookup cache policy for successful lookups:
#
# any negative value: caching forever
# any positive value: the number of seconds to cache an address for
# zero: do not cache
#
# default value is forever (FOREVER). For security reasons, this
# caching is made forever when a security manager is set. When a security
# manager is not set, the default behavior in this implementation
# is to cache for 30 seconds.
#
# NOTE: setting this to anything other than the default value can have
# serious security implications. Do not set it unless
# you are sure you are not exposed to DNS spoofing attack.
#
#networkaddress.cache.ttl=-1
๋ฐ๋ผ์, ์ ์์ ์ผ๋ก ์คํ์ค์ธ ์ ํ๋ฆฌ์ผ์ด์ ์์ ๊ฐ์๊ธฐ DNS ์์ฒญ์ด ์ํ๋์๋์ง๋ฅผ ์ดํดํ ์ ์๊ณ , ํด๋น ์์ฒญ์ ์ํํ ์์ ์ DNS ์๋ฒ์์๋ ์์ฒญ์ ๋ํ ์๋ต์ ํ ์ ์์๋ค๋ ๊ฒ์ (failed to query external DNS server ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํตํด) ์ ์ ์๊ฒ ๋ฉ๋๋ค.
DNS ์์ฒญ์ด ์คํจํ ์ด์ โ
dig sqs.ap-northeast-2.amazonaws.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.amzn2.13.8 <<>> sqs.ap-northeast-2.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45612
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;sqs.ap-northeast-2.amazonaws.com. IN A
;; ANSWER SECTION:
sqs.ap-northeast-2.amazonaws.com. 16 IN A 3.34.228.79
;; Query time: 0 msec
;; SERVER: 192.168.0.2#53(192.168.0.2)
;; WHEN: Sun Nov 03 05:53:46 UTC 2024
;; MSG SIZE rcvd: 77
dig(๋๋ nslookup) ๋ช ๋ น์ด๋ฅผ ํตํด sqs.ap-northeast-2.amazonaws.com์ ๋ํ DNS ์ง์๋ฅผ ์ํํด๋ณผ ์ ์์ต๋๋ค. ์ ์์ ์ธ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด UDP๋ฅผ ํตํด DNS ์ง์์ ๋ํ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ ์ ์์ด์ผ ํฉ๋๋ค. ์์ ์ค๋ฅ์ ๋ํ ๋ฉ์์ง๋ฅผ ์ดํด๋ณด๋ฉด DNS ์ง์์ ๋ํ ์์ฒญ์ด ํ์์์ ๋์ด๋ฒ๋ ธ์ต๋๋ค. ๋ค๋ฆ๊ฒ ์๊ฒ๋ ์ ๋ณด์ด์ง๋ง ์ฌ๋ด์์ ํ๋ก์ ํธ ๊ด๋ จ ๋ด์ฉ์ ๊ณต์ ํ๊ธฐ ์ํด ๊ตฌ๊ธ ๋๋ผ์ด๋ธ์ ์ฝ 60GB ์ ๋ ๋๋ ๋ฌธ์๋ฅผ ์ ๋ก๋ ๋ฐ ๋ค์ด๋ก๋ ํ๋ค๊ณ ํฉ๋๋ค.
์ฌ์ค ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฅ์์ ํฌ๋ฆฌํฐ์ปฌํ ๋ฌธ์ ๋ ์๋๋ค โ
AWS SDK๋ฅผ ํตํด SQS ๋ฉ์์ง ์ฒ๋ฆฌ๋ฅผ ์ํํ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฌ์ฉ์์๊ฒ ์ ๋ฌ๋ ์นด์นด์ค ์๋ฆผํก ๋ฉ์์ง์ ๋ํ ๋ฐ์ก ๊ฒฐ๊ณผ๋ฅผ ์์ ํ์ฌ ์ฒ๋ฆฌํ๊ธฐ ์ํ ์์ ์ ์ํํฉ๋๋ค. ๋ฐ๋ผ์, ์ผ์์ ์ผ๋ก SQS์ ์ ์ฅ๋ ์๋ฆผํก ๊ฒฐ๊ณผ ๋ฉ์์ง๋ฅผ ์ฒ๋ฆฌํ์ง ๋ชปํ๋๋ผ๋ (์ง์์ ์ผ๋ก SQS ํต์ ์ ์ํํ ์ ์๋ ์ํ๊ฐ ์๋๋ผ๋ฉด) ํฌ๋ฆฌํฐ์ปฌํ ๋ฌธ์ ๋ ์๋๋๋ค. ๊ทธ๋ผ์๋ ๋ถ๊ตฌํ๊ณ DNS ์ค๋ฅ์ ๋ํ ์๋ฆผ์ ํ์ธํ๊ณ ์ ํ๋ฆฌ์ผ์ด์ ๊ธฐ๋ฅ์ ๋ํด ์ฃผ๊ธฐ์ ์ธ ๋ชจ๋ํฐ๋ง์ ํ์ํ ๋ถ๋ถ์ ๋๋ค.
์๋ฌดํผ ํดํ๋!...