I have an fairly old twitter bot that's been running for several years no problem. It uses twitter4j, running on JRE 1.6. Two days ago I suddenly started getting SocketExceptions:
Exception in thread "main" Connection reset
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=7e95ed42 or
http://www.google.co.jp/search?q=8a72206c
TwitterException{exceptionCode=[7e95ed42-8a72206c faf0771e-c3d1e8db], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.7}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:185)
at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
at twitter4j.HttpClientBase.get(HttpClientBase.java:75)
at twitter4j.TwitterImpl.get(TwitterImpl.java:2084)
at twitter4j.TwitterImpl.getFriendsList(TwitterImpl.java:808)
at twitter4j.TwitterImpl.getFriendsList(TwitterImpl.java:803)
at uk.co.twinance.Fetcher.getAvatars(Fetcher.java:167)
at uk.co.twinance.Fetcher.run(Fetcher.java:103)
at uk.co.twinance.Fetcher.main(Fetcher.java:203)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:422)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:460)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:863)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1215)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1199)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
at twitter4j.HttpResponseImpl.<init>(HttpResponseImpl.java:35)
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:149)
... 8 more
I get this on my linode and two home laptops running Ubuntu 11 and 18, and I get the Exception for every single request.
After much faffing I discovered that if I switch the runtime to JRE 11 it works flawlessly! No Exceptions at all.
So - i guess something on the twitter end has changed recently (given the issue is reproducible on 3 machines), but I am at a loss to understand how the JRE could be effecting network requests in a way that would cause a problem with twitter.
Any thoughts?
Your problem is a combination of the following issues:
Java 6.0 only supports SSL/TLS up to TLS1.0; see How to use TLS 1.2 in Java 6
On Monday 15th July 2019, Twitter turned off support for TLS 1.0 and TLS 1.1 in their public APIs. (Source https://www.thesslstore.com/blog/twitter-will-deprecate-support-for-tls-1-0-tls-1-1-on-july-15/)
Taken together, this explains why your Java 6 based twitter bot has recently stopped working.
Note that Java 6.0 is end-of-life. Public updates ended in April 2013. Even Oracle's "Extended Support" option for Java 6.0 ceased in December 2018.
(Source: https://www.oracle.com/technetwork/java/java-se-support-roadmap.html)
So the best solution to your problem will be to update the Java platform your twitter bot runs on. (And as it turns out, the upgrade was simple.)
Upgrading Java has another benefit. You will be applying about 6 years of accumulated security patches, bug fixes and performance enhancements to your Java platform.
Also note that TLS 1.2 was finalised in 2008. The latest version is TLS 1.3 (finalised 2018). TLS 1.0 and TLS 1.1 are due to be officially deprecated in 2020.
(Source https://en.wikipedia.org/wiki/Transport_Layer_Security)
This continual evolution of key internet standards like SSL/TLS is another reason why it is advisable to not let your Java platform to drop too far behind.