rubenlagus / TelegramBots

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

"SSL peer shut down incorrectly" #720

Closed Quicksy closed 4 years ago

Quicksy commented 4 years ago

Today suddenly all my bots cannot get connected to the Telegram API. The bot starts, then waiting some time and then show the following stacktrace:

        at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:87)
        at org.telegram.telegrambots.bots.TelegramLongPollingBot.clearWebhook(TelegramLongPollingBot.java:25)
        at org.telegram.telegrambots.meta.TelegramBotsApi.registerBot(TelegramBotsApi.java:120)
        at com.plantCourier.PlantCourier.main(PlantCourier.java:47)
Caused by: org.telegram.telegrambots.meta.exceptions.TelegramApiException: Unable to execute deleteWebhook method
        at org.telegram.telegrambots.bots.DefaultAbsSender.sendApiMethod(DefaultAbsSender.java:727)
        at org.telegram.telegrambots.meta.bots.AbsSender.execute(AbsSender.java:47)
        at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:82)
        ... 3 more
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
        at org.telegram.telegrambots.bots.DefaultAbsSender.sendHttpPostRequest(DefaultAbsSender.java:741)
        at org.telegram.telegrambots.bots.DefaultAbsSender.sendMethodRequest(DefaultAbsSender.java:737)
        at org.telegram.telegrambots.bots.DefaultAbsSender.sendApiMethod(DefaultAbsSender.java:724)
        ... 5 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:505)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
        ... 22 more

I found in the Internet, that sometimes this error can be resolved by adding the following code into the program: System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); - but it didn't help at all. Could you suggest what should I do or where I need to dig to find the solution on this?

galimru commented 4 years ago

It would be great if you run the app with args -Djavax.net.debug=ssl,handshake and post result here.

Quicksy commented 4 years ago

log2.log

Here it is.

galimru commented 4 years ago

It seems for me, the cause is that OpenJDK doesn't contain root certificates out of box. Try to install them separately like that

apt-get install ca-certificates-java
Quicksy commented 4 years ago

Suddenly it was a problem with OpenJDK 8 - I tired to purge it and install OpenJDK 9 instead - and bots got connected immediately. Thank you for your help :)