I am facing a problem with CXF framework trying to connect to a https backend service. Since the service is out side of my network I am using a proxy to connect. I am getting a SocketTimedOutException when I set the readTimeout Value to like 60000 which is the default. When I set the timeout to 0(infinite) it gives a connectionResetException after a while. I wrote a program on my own which used HttpsUrlConnection to connect to the same service with proxy and I am able to work with it.
I was initially under the feeling that the connection itself was not happening but later I came to know that that would have thrown a ConnectException rather than a socketException. It gave me some relief , but I want to know how I can deal with the SocketException, both the timeout and the Connection Reset.
Please explain to me whoever knows about this.
Thanks,
Sachin
You should blame on your network or your proxy, but not your codes. SocketTimedOutException and ConnectionTimedOutException are thrown when network is blocked or weak. So, the solution to both exceptions is smoothening your network.
Related
The problem:
I am having some strange behaviour from a Jetty server (rest over https) when some client connections are closed (client-side) before the server has had time to reply. Normally this is well managed and expected by a webserver/application server but in a specific instance something breaks the server that stops replying.
I am trying to reproduce programmatically and locally the issue, opening a client connection and closing it before the server has had time to reply, but I do not have much experience with a situation like this, normally the clients I write are expected to not die immediately.
I am not interested in the language/application I have to use to replicate my case, it can be a Java program, a netcat command, telnet, dotnetcore... The only limit I have is that it should run on a Kubernetes pod, if possible.
I am trying to use Java to open a socket then close it immediately, or to create an Http client and stop it immediately after a request sent, but with no luck at the moment.
At the same time I am looking at netcat, but I fear it's too low level for a rest request.
I have a java client app and a java server app.
My client can have network slowdown.
My client performs SOAP webservices to my server app. The problem is that sometimes the client reach its timeout (40sec) because the network is really, really bad.
For the client app this request is a fail, and it retry the same call a bit later. But the server had already integrated the data from client, and I get violated keys error from my ORM.
I do not want to prolong the timeout on the client side.
My question is: when the client timeout, is there a way to rollback everything on the server side ?
Thanks
One of the options to solve it is to set some flag/status in the database when request is accepted by server. Something like inProcessing. And change this flag to Complete after successful data processing.
When client will retry the same call later you can check this flag and if flag=inProcessing or Complete don't do any date processing.
I have a REST service that calls another remote service.
Most of the time the communication works fine, but occasionally, I encounter
org.apache.cxf.jaxrs.client.ClientWebApplicationException:
org.apache.cxf.interceptor.Fault: Could not send Message.
org.apache.cxf.interceptor.Fault: Could not send Message.
SocketException invoking https://url: Unexpected end of file from server
I did some research and found it's the remote server shut down the connection unexpectedly.
It really puzzles me, because everything (input, header, etc) is the same and I was testing with a small amount of requests only like (50-100), I have tried both in sequence and in parallel, only a few will encounter this issue.
Why would this happen? Do I have to ask the remote server to reconfigure, or do I have to implement a retry pattern in my service in this case?
Any hint?
Thanks
P.S
I am using
org.apache.cxf.jaxrs.client.WebClient
to invoke the remote service. Will it make any difference if I switch to HttpClient?
I have an apache proxy between browser and my custom web server. So after starting the webserver, I can access my web application for like 4-5 hours. After that I get this error
Proxy Error The proxy server received an invalid response from an
upstream server. The proxy server could not handle the request GET /.
Reason: Error reading from remote server
To access the web application again, I have to restart the web server. I tried to check the log I got from my web server and only error in that log , I am finding is this
com.mysql.jdbc.CommunicationsException: Communications link failure
due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException MESSAGE: Connection timed out
STACKTRACE:
java.net.SocketException: Connection timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:146)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1910)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3099)
at com.mysql.jdbc.Statement.execute(Statement.java:695)
at hra.database.Pool.getConnection(Pool.java:62)
** END NESTED EXCEPTION **
Last packet sent to the server was 925624 ms ago.
And I tried to fix this database error, but I still get the above mentioned proxy error, so definitely the log information is not useful.
This is what I am getting from Apache Proxy log
(70007)The timeout specified has expired: proxy: error reading status
line from remote server
Does anyone know what can be the issue or any helpful pointers to fix this issue?
apache proxy fails because customwebserver does not answer. your
customwebserver logs a crash waiting for mysql to answer. rebooting
customwebserver fixes it, so mysql is not the problem. it looks like the problem the way your customwebserver handles its connections to mysql.
can we see your jdbc config? do you have autoReconnect=true ?
What is likely happening is that your up-stream server is shutting itself down because of inactivity. Find the setting on the server that controls that and turn it up.
I can see that you see two connection timeout errors
Apache Proxy Web server timing out while connecting to custom web server
Custom web server timing out while connecting to database
If the timeout set on proxy server is less than timeout set for database connection, before the database connection times out, proxy server would time out as well.
As a first thing resolve all DB connectivity issues and test your application by directly connecting to custom web server (not via proxy).
Observe and identify normal response time and max response time.
Set proxy time out ProxyTimeout to be a value that is more than (max response time) + (network delay)
If possible you may share proxy server configurations to help you further.
I think like stated by the previous answer that you encounter a timeout raised by one of the members of your infrastructure:
server
network device (routers are clever beasts but firewalls can be clever too)
Did you setup a real connection pool ? Using heart beat mechanism to keep alive connections ?
This induces some network traffic but avoids such problems ?
Try to use a network capture tool to have many logs to analyze
HTH
jerome
I'm working on an Android application that requires the use of HttpClient in order to upload a file from the Android device to a web server. The file I'm uploading can reach sizes up to 1 Gb, and so timeouts can occur if the device loses connection during the upload. The weird thing is that the timeout I set for the socket doesn't seem to have any effect. The application would just hang whenever I lose connection instead of raising the SocketTimeoutException.
I tried using:
HttpConnectionParams.setConnectionTimeout(params, CrashLogParams.TIMEOUT);
HttpConnectionParams.setSoTimeout(params, CrashLogParams.TIMEOUT);
but this only worked for the connection timeout, not the socket timeout. Also I tried:
HttpParams p = httpclient.getParams();
p.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);
p.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
The reason I know that connection timeout works is because, I would get the exception for connection timeout after executing
httpclient.execute(httppost);
The application seems to hang when connection is lost during upload, but after the application has successfully made a connection to the server.
To test my app, I disabled the network at different times to see how the application would react. If I disable the network before sending the request, I get a connection error and my application can gracefully handle that, but if I disable it during upload the application hangs. Of course I'm doing all these requests through AsyncTasks, so the main UI Thread doesn't crash. I'm just wondering if there is any other way to make sure that the socket will timeout upon not receiving any data, or if I'm missing anything here. I've read many blogs and posts, but most of them just suggest using SO_TIMEOUT which doesn't work for me.
sotimeout not working in a multipart http post on android 2.1
Are you creating your own ClientConnectionManager? Take a look at the source for AndroidHttpClient.newInstance().
They create a new BasicHttpParams object and pass it to the constructors for both a ThreadSafeClientConnectionManager and the DefaultHttpClient. I don't see a way to set parameters on the ClientConnectionManager except in the constructor.
I'm facing the same problem as you, with the same use case. It happens on a samsung galaxy s2 running android 2.3.6 but not with the same device on 4.x . Unfortunately this is exactly the device my customer uses, and it runs fine on roughly 10 other test devices with various Android versions and constructors...
I spent hours trying with HttpUrlConnection library instead of HttpClient from Apache, but the end result is the same. AndroidHttpClient shows the same behavior. This leads me to say that it sounds like an hardware implementation or OS related problem...
The only workaround I found was to put the HttpClient.execute() method in a separate thread and call thread.join(timeout) as a security to stop the thread if anything goes wrong. The drawback is when upload runs fine but takes longer than the timeout, the request is interrupted...
If you found something in the meantime, I would greatly appreciate if you could share it.