rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

Network Issue #890

Closed ansidev closed 3 years ago

ansidev commented 3 years ago

I am running my applications using Docker and the application will print the following logs after running a long time then it does not work anymore. Rebooting the application does not solve the issue. Do you know what is the root cause and how to fix this issue? Thank you!

Log:

java.net.UnknownHostException: api.telegram.org
    at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797) ~[na:na]
    at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505) ~[na:na]
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364) ~[na:na]
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298) ~[na:na]
    at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:112) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.12.jar!/:4.5.12]
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.getUpdatesFromServer(DefaultBotSession.java:254) ~[telegrambots-4.9.jar!/:na]
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:195) ~[telegrambots-4.9.jar!/:na]

build.gradle dependency

implementation group: 'org.telegram', name: 'telegrambots-spring-boot-starter', version: '4.9'
Chase22 commented 3 years ago

That could be a DNS issue. Is the bot running in Russia or China? These are known for blocking connections to telegram, you might have to set a Proxy

ansidev commented 3 years ago

That could be a DNS issue. Is the bot running in Russia or China? These are known for blocking connections to telegram, you might have to set a Proxy

The server is located in Vietnam. Do you have any suggestion about proxy?

ansidev commented 3 years ago

I solved my problem by add --dns 8.8.8.8 to the Docker command to config the DNS server for the Docker container.

lee-qinghua commented 1 year ago

i am in China ,i met the same question ,i tried to change the dns to 8.8.8.8,but it does`t work ,who can help me