users@jersey.java.net

[Jersey] Re: "Error: Writing to server" - Occuring only on ubuntu

From: Pantelis Natsiavas <natsiavas_at_gmail.com>
Date: Tue, 27 Sep 2016 10:46:41 +0300

Pavel was right.

The solution is on the TCP level and not on the JVM version or
configuration. I have changed the my ubuntu networking settings and the
error is gone. I suppose, it occured only to large HTTP requests, because
the TCP windows were too small or something.

I followed the instructions in
http://www.slashroot.in/linux-network-tcp-performance-tuning-sysctl article
to set the following settings:

net.ipv4.tcp_window_scaling = 1
> net.core.rmem_max = 16777216
> net.ipv4.tcp_rmem = 4096 187380 16777216
> net.ipv4.tcp_wmem = 4096 187380 16777216


Please note that the error occured on an HTTP request with a load of about
90kbytes. I needed to play around with the value of the window assigned to
each TCP connection (187380) in order to succeed.

Regards,
Pantelis Natsiavas

2016-09-27 9:46 GMT+03:00 Pantelis Natsiavas <natsiavas_at_gmail.com>:

> Thank you very much Pavel for your time. I really appreciate it.
>
> I have run the same test on another Ubuntu PC (similar setup) and the same
> problem occurs. Both of these Ubuntu machines where the problem came up
> have been setup by me for development purposes (one in the lab, one in my
> home office, different networks/subnets, targeting the same server).
> Therefore, if there were any special network configurations I would have
> known.
>
> Since you say this is a TCP level error, I guess there might be a default
> parameter in Ubuntu that causes the problem in large HTTP posts. Do you
> have any suggestions? What kind of parameters could affect such behavior?
> Do you have any idea where to search?
>
> Regards,
> Pantelis.
>
>
>
> 2016-09-26 19:05 GMT+03:00 Pavel Bucek <pavel.bucek_at_oracle.com>:
>
>> Hi Pantelis,
>>
>> this is not a know issue.
>>
>> Oracle JDK should work, you don't need to consider switching to Open JDK.
>>
>> We are using linux machines as our test infra, so I'd think this should
>> be stable and your issue might be related to configuration of your box. The
>> error you see is not something we can influence form Jersey, seems like
>> underlying TCP connections is closed at some point and then the IOException
>> is thrown when the client tries to write into that.
>>
>> If I were you, I'd try to compare network level config of the windows
>> machine and the linux box.
>>
>> Regards,
>> Pavel
>>
>> On 26/09/16 08:49, Pantelis Natsiavas wrote:
>>
>> Hi everybody.
>>
>> I am using a jar file implementing custom functionality which uses jersey
>> as REST client (version 2.22.1). While everything seems to work fine for a
>> few calls, for a specific HTTP call I get a "*Error: Writing to server*",
>> but only when running in ubuntu.
>>
>> The error occurs when running a unit test on my development PC. My
>> development PC is an Ubuntu 16.04 with Oracle JDK:
>>
>> ~$ java -version
>> java version "1.8.0_101"
>> Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
>> Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
>>
>> Running the same test from a windows machine, gives me no error. On my
>> windows machine:
>>
>> java -version
>> java version "1.8.0_102"
>> Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
>> Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
>>
>> I can only suppose that the jvm version is the cause of the error. Is
>> this a known issue? Does this apply to the ubuntu jvms in general, or only
>> to the specific version? Should changing to Open JDK correct the error?
>> Could you please provide a hint on how I could avoid this error while being
>> on Ubuntu?
>>
>> The full error's stacktrace is:
>> javax.ws.rs.ProcessingException: java.io.IOException: Error writing to
>> server
>> at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(
>> HttpUrlConnector.java:287)
>> at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRunti
>> me.java:255)
>> at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyIn
>> vocation.java:684)
>> at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyIn
>> vocation.java:681)
>> at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
>> at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
>> at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
>> at org.glassfish.jersey.process.internal.RequestScope.runInScop
>> e(RequestScope.java:444)
>> at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyIn
>> vocation.java:681)
>> at org.glassfish.jersey.client.JerseyInvocation$Builder.method(
>> JerseyInvocation.java:437)
>> at org.glassfish.jersey.client.JerseyInvocation$Builder.put(Jer
>> seyInvocation.java:326)
>> ....
>> Caused by: java.io.IOException: Error writing to server
>> at sun.net.www.protocol.http.HttpURLConnection.writeRequests(Ht
>> tpURLConnection.java:666)
>> at sun.net.www.protocol.http.HttpURLConnection.writeRequests(Ht
>> tpURLConnection.java:678)
>> at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(
>> HttpURLConnection.java:1534)
>> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(H
>> ttpURLConnection.java:1441)
>> at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
>> at org.glassfish.jersey.client.internal.HttpUrlConnector._apply
>> (HttpUrlConnector.java:394)
>> at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(
>> HttpUrlConnector.java:285)
>> ... 40 more
>>
>> Kind regards,
>> Pantelis Natsiavas
>>
>>
>>
>