0

The NullPointerException doesn't occur when a single request is made. But when I make a series of requests to the same API - around 1000, at around the 601st request, the connection fails and the exception trace is printed. Someone please help me with it. I've been trying to debug it, but I am unable to get the root cause.

java.lang.NullPointerException

at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:468)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1340)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1315)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:264)
at com.mytest.TestApplication.httpclient.Request.call(Request.java:143)
at com.mytest.TestApplication.httpclient.Request.call(Request.java:37)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
egemenakturk
  • 365
  • 1
  • 17
  • Does every connection fail after that? – ControlAltDel Jul 06 '20 at 17:18
  • @ControlAltDel yeah, every connection fails after that – Shri Kumar D Jul 06 '20 at 20:45
  • 1
    It sounds like you are running out of resources. Try this: After your 500th connection, try making sure all of your previous connections are closed and finalized, then call System.gc(), and then see if you get the exception after that. One thing that I can tell you is that I once made a pass-through proxy server, and as I recall that server could handle at least 1500 connections at once. So based on that it seems unlikely to be a problem of running out of sockets... Otherwise, I don't know – ControlAltDel Jul 06 '20 at 21:00
  • You know, I have a suspicion it might be your router or a switch somewhere trying to stop you from a suspected DOS attack. – ControlAltDel Jul 06 '20 at 21:02
  • 2
    It might also be helpful to provide a code snippet which demonstrates how you are serving the requests, as well as how you are testing the 1000 requests. Also are there any proxies between client and server? – James Powis Jul 07 '20 at 05:46
  • @JamesPowis This would be my sample code - `int count = 1000; ExecutorService migrationWorkerPool = Executors.newFixedThreadPool(10); while(count-- > 0) { //count is n, n<2000 Request r = new Request(); migrationWorkerPool.submit(r); } migrationWorkerPool.shutdown(); } class Request implements Callable{ HttpsURLConnection con; @Override public Integer call() throws Exception { try { URL url = new URL("https://localhost:9090/RequestAPI"); con =(HttpsURLConnection) url.openConnection(); } catch(Exception ex){ } } ` – Shri Kumar D Jul 07 '20 at 12:23
  • @JamesPowis, Also there are no proxies between client and the server. – Shri Kumar D Jul 07 '20 at 12:51
  • It might also be helpful to tell which version of java you are using. What is the full output of : `java -version`? – daniel Jul 08 '20 at 10:28
  • @daniel openjdk version "1.8.0_252" OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09) OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode) – Shri Kumar D Jul 09 '20 at 15:14
  • This looks that this is this line: http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/file/db9fc4b93cfe/src/share/classes/sun/net/www/protocol/https/HttpsClient.java#l468 I will hazard a guess: the factory that is used at line 436 or 449 has returned null, which should not be possible with the default socket factory. Is your application using a custom SSLSocketFactory? I would start looking from there. – daniel Jul 10 '20 at 17:24
  • Sorry for the late response, @daniel. I looked into that angle. But we use the default socketFactory. That was what was puzzling me. Null shouldn't be returned there. – Shri Kumar D Aug 03 '20 at 15:54

0 Answers0