UnknownHostException
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 μ€λ₯μ λν μλ¦Όμ νμΈνκ³ μ ν리μΌμ΄μ κΈ°λ₯μ λν΄ μ£ΌκΈ°μ μΈ λͺ¨λν°λ§μ νμν λΆλΆμ λλ€.
μλ¬΄νΌ ν΄νλ!β¦