[ 
https://issues.apache.org/jira/browse/HTTPCORE-414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15011752#comment-15011752
 ] 

Oleg Kalnichevski commented on HTTPCORE-414:
--------------------------------------------

Dominique,
It is a classic race condition. 
(1) The server _apparently_ has been configured to close connections after 5 
seconds of inactivity. 
(2) The client polls every < 5 seconds. It leases a persistent connection from 
the pool which it is still valid. All is well.
(3) The client polls every 5 seconds. It leases a persistent connection from 
the pool assuming it is still valid. The server closes the connection on its 
end while the client is still busy executing the request. Message exchange 
fails with ConnectionClosedException on the client side. Kaboom.  
(4) The client polls every > 5 seconds. Persistent connections get closed by 
the server after 5 seconds of inactivity and gets evicted from the pool of 
connections on the client side. When the client requests a connection from the 
pool there is none available. Client opens a new connection. All is well.

Oleg

> HTTP Connection closed when polling an API every 5 seconds
> ----------------------------------------------------------
>
>                 Key: HTTPCORE-414
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-414
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore NIO
>    Affects Versions: 4.4.4
>         Environment: OS : Linux Ubuntu 14.04 LTS
> Software : Java 1.8
> Java source code available at the following link :
> https://gist.github.com/dominiquemongelli/34e3588c5a1436276dff#file-httpcoreniosample
> The java program uses the following libraries :
> - httpclient 4.5.1
> - httpcore-nio 4.4.4
> - httpasyncclient 4.1
> - httpcore 4.4.4
>            Reporter: Dominique Mongelli
>            Priority: Minor
>              Labels: connectionclosed, http, http304, httpcore
>
> Scenario to reproduce the bug :
> - The java source code simulates 10 pollings on the following API  
> http://www.typeunsafe.org/api/temperatures/69 (using httpasyncclient) with 5 
> seconds polling frequency.
> - Compile and run the source code provided.
> - Current result : after some polling correctly done, the execution throws 
> the following exception :
> {code:title=|borderStyle=solid}
> Exception in thread "main" java.util.concurrent.ExecutionException: 
> org.apache.http.ConnectionClosedException: Connection closed
>       at org.apache.http.concurrent.BasicFuture.getResult(BasicFuture.java:70)
>       at org.apache.http.concurrent.BasicFuture.get(BasicFuture.java:80)
>       at HttpCoreSample.main(HttpCoreSample.java:31)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:483)
>       at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
> Caused by: org.apache.http.ConnectionClosedException: Connection closed
>       at 
> org.apache.http.nio.protocol.HttpAsyncRequestExecutor.endOfInput(HttpAsyncRequestExecutor.java:321)
>       at 
> org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:263)
>       at 
> org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
>       at 
> org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
>       at 
> org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:116)
>       at 
> org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:164)
>       at 
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:339)
>       at 
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:317)
>       at 
> org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:278)
>       at 
> org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106)
>       at 
> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:590)
>       at java.lang.Thread.run(Thread.java:745)
> {code}
> Important things to mention :
> - The issue does not occur with another API (for example API 
> https://api.bitcoinaverage.com/ticker/global/EUR/)
> - The issue is reproductible only with a 5 seconds polling frequency. If 
> polling frequency is set to 10 seconds, then the issue is not reproductible 
> anymore.
> The polling frequency can be updated via :
> {code:title= |borderStyle=solid}
> Thread.sleep(POLLING_FREQUENCY_IN_MS);
> {code}
> - The API uses within the source code 
> (http://www.typeunsafe.org/api/temperatures/69) can return a 304 http status 
> when no data has been updated.
> - The API uses a Varnish cache layer.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to