Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.59k stars 593 forks source link

Can't sense connection closed by server in some extreme circumstances #403

Closed dlmu-lq closed 2 years ago

dlmu-lq commented 3 years ago

Describe the bug Server slb idle connections will be closed in 15s,but the time in client is 30s. So in some extreme circumstance,unirest client will use connections closed by server and throw an exception like: kong.unirest.UnirestException: org.apache.http.NoHttpResponseException: ** failed to respond

is there anyway to avoid this?

ryber commented 3 years ago

as the error implies the error is in Apache. You could create a custom Apache client for unirest that is configured with a NoConnectionReuseStrategy. that may have other negative performance consequences

ryber commented 3 years ago

I would note that using that strategy might help with a very flakey server but in the end this is a valid exception

dlmu-lq commented 3 years ago

@ryber Thank you for your reply, noticed that unirest have a thread AsyncIdleConnectionMonitorThread, do the work : close connections idled 30s, any consideration to expose 30 as a config?

dlmu-lq commented 3 years ago

@ryber Or any consideration to allow users to custom set ConnectionKeepAliveStrategy for httpClient may solve this problem?

ryber commented 3 years ago

I try to avoid getting too much into configuring apache with advanced things like the Connection Strategies. Users can configure an entire client to use. We could expose the IdleConnectionMonitor, although that is going away in the next major version because Unirest is switching to the Java 11 client

ryber commented 2 years ago

I'm going to close this. There is always the option to use the advanced features of Apache with a custom apache client. It's quite easy to set.