Frequent Read Timeouts Using Box Java SDK
I've written a Box App that, by its very nature, needs to connect to the Box API frequently--nearly constantly, in fact. It relies on polling the Enterprise Events log, and then performs actions based on what is contained within those events. I'm using Box Java SDK 20.5.1, the latest release as of this post. It utilizes JWT auth.
I expect the potential of hitting the rate limit frequently, but what seems to happen more are read timeouts. If I don't set timeouts, the connections may hang indefinitely. If I do set timeouts, they can occur several times a minute, or take several minutes but still occur, even if I adjust the polling frequency to, say, 15 seconds apart, and the read timeout to 10 seconds. I've tried adjusting the keepalive and maxConnections properties for HttpURLConnection but to no avail.
This is the stack trace I get (using OpenJDK 8 on CentOS):
com.box.sdk.BoxAPIException: Couldn't connect to the Box API due to a network error.
at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:663)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:382)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:349)
at com.box.sdk.EventLog.getEnterpriseEvents(EventLog.java:134)
at com.box.sdk.EventLog.getEnterpriseEvents(EventLog.java:63)
.....
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:990)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:948)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:159 3)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498 )
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionIm pl.java:352)
at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:661)
... 18 common frames omitted
which is when it attempts to get a response code, and it seems the server sends nothing back.
I'm not sure if it's the Box API blocking the app after a certain amount of connections, or if it is some other cause. Is there something I'm missing to reduce the incidence of these read timeouts occurring?
Please sign in to leave a comment.
Comments
0 comments