ID 981887, 개발언어는 자바 입니다.
먼저 카카오계정 에서 인가 코드를 받아오고
토큰을 받기 위해 https://kauth.kakao.com/oauth/token 여기로 요청을 보내면
응답을 1분 동안 기다리다가, connection timed out 이 뜹니다.
아예 안 되면 방화벽 문제라고 생각하겠는데, 어떨 때는 또 토큰을 받아와서 잘 진행이 됩니다.
코드 전문입니다.
URL url = null;
HttpURLConnection conn = null;
url = new URL(resValue.get("tokenUrl"));
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
StringBuilder sb = new StringBuilder();
sb.append("grant_type=authorization_code");
sb.append("&client_id=" + resValue.get("clientId"));
if(platform.equals("KAKAO")) {
sb.append("&redirect_uri=" + resValue.get("redirectUrl"));
sb.append("&code=" + resValue.get("code"));
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
/* 여기로 들어가서 connection timed out 이 뜹니다. */
try(BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()))){
bw.write(sb.toString());
} catch(IOException e){
~~~~
}
도움 부탁드립니다. 감사합니다.
안녕하세요.
서비스측 요청은 오류 포함하여 모두 즉시 응답되었습니다.
timeout 경우 서비스측 방화벽 및 네트워크 환경에 따라 발생되므로 확인 부탁드립니다.
그리고, redirectUrl 값은 URL인코딩하여 전송 부탁 드립니다.
말씀해주신 대로 방화벽 확인을 위해 서버에서 직접 연결을 시도했습니다.
curl -v https://kauth.kakao.com
해당 명령어로 접근하면
203.133.166.32
27.0.237.15
이 두 IP 로 넘어가는데
연결이 될 때는 두 IP 모두 HTTP/1.1 302 Found 응답이 잘 넘어옵니다.
그런데 잘 되는건 잠깐이고, 다시 시도해보면 두 IP 모두 응답이 넘어오질 않고
1분쯤 기다리면 연결 시간이 초과되어 curl: (7) couldn’t connect to host 라는 에러 메세지가 출력됩니다.
정리하자면 됐다가 안 됐다가 하는데, 안 되는 시간이 훨씬 깁니다.
제가 서버를 잘 몰라서 이게 방화벽이 뚫렸으면 뚫린 거 아닌지
됐다가 안됐다가 하는게 맞는 건지 머리가 복잡합니다.
해당 상황에 대한 경험이나 해결 방법이 있으시면 도움 부탁드리겠습니다.
안녕하세요.
번거로우시겠지만, curl -v https://kauth.kakao.com
실행 결과 첨부 부탁드립니다.
연결이 될 때
curl -v https://kauth.kakao.com
* About to connect() to kauth.kakao.com port 443 (#0)
* Trying 27.0.237.15... connected
* Connected to kauth.kakao.com (27.0.237.15) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject: CN=*.kakao.com,O=Kakao Corp.,L=Jeju-si,ST=Jeju-do,C=KR
* start date: Aug 31 00:00:00 2023 GMT
* expire date: Sep 29 23:59:59 2024 GMT
* common name: *.kakao.com
* issuer: CN=Thawte TLS RSA CA G1,OU=www.digicert.com,O=DigiCert Inc,C=US
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.44 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: kauth.kakao.com
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Tue, 02 Jan 2024 02:40:16 GMT
< Content-Length: 0
< Connection: keep-alive
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Referrer-Policy: strict-origin-when-cross-origin
< X-Frame-Options: DENY
< Location: https://accounts.kakao.com/login?continue=https%3A%2F%2Fkauth.kakao.com%2Foauth%2Fauthorize%3Fthrough_account%3Dtrue
< Kakao: Talk
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Headers: Authorization, KA, Origin, X-Requested-With, Content-Type, Accept
<
* Connection #0 to host kauth.kakao.com left intact
* Closing connection #0
연결이 안될 때
curl -v https://kauth.kakao.com
* About to connect() to kauth.kakao.com port 443 (#0)
* Trying 27.0.237.15... Connection timed out
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
확인해 보니 관련한 이슈가 리포팅된바 없습니다.
번거로우시겠지만, traceroute 를 사용하여, 타임아웃 발생 위치를 확인 부탁드립니다.
sudo traceroute -T kauth.kakao.com
traceroute to kauth.kakao.com (203.133.166.32), 30 hops max, 60 byte packets
1 10.10.10.254 (10.10.10.254) 0.117 ms 0.104 ms 0.098 ms
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 * * *
29 * * *
30 * * *
나가는 길도 못 찾을 때
sudo traceroute -T kauth.kakao.com
traceroute to kauth.kakao.com (203.133.166.32), 30 hops max, 60 byte packets
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 * * *
29 * * *
30 * * *
타 플랫폼에 요청을 보냈을 때
sudo traceroute -T nid.naver.com
traceroute to nid.naver.com (125.209.226.33), 30 hops max, 60 byte packets
1 10.10.10.254 (10.10.10.254) 0.101 ms 0.100 ms 0.098 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 125.209.226.33 (125.209.226.33) 8.056 ms 7.055 ms 6.052 ms
sudo traceroute -T accounts.google.com
traceroute to accounts.google.com (142.250.206.237), 30 hops max, 60 byte packets
1 10.10.10.254 (10.10.10.254) 1.243 ms 1.243 ms 1.394 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 kix06s10-in-f13.1e100.net (142.250.206.237) 26.696 ms 28.667 ms *
안녕하세요
로그에서 *
로 다수 표시되는 것으로 보아
서비스측 방화벽이 원인인 것으로 보입니다.
방화벽측 아웃바운드 로그를 확인해 보시면 좋을것 같습니다.
방화벽 확인하여 해결했습니다.
kauth.kakao.com 와 kapi.kakao.com 를 도메인 이름으로 방화벽 허용을 해놨는데
서버 이중화를 잘 인식하지 못해서, api의 1번 서버 2번 서버로 번갈아 요청을 보낼 때 문제가 생기고 있었습니다.
203.133.166.32, 27.0.237.15, 203.133.166.33, 211.249.200.134 의 고정 IP 를 모두 허용하여 문제 해결했습니다.
도움 주셔서 감사합니다.
1개의 좋아요