hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitry Potapov <potapo...@gmail.com>
Subject Re: [jira] [Resolved] (HTTPCORE-377) Allow to enable SO_LINGER option with zero timeout
Date Wed, 23 Apr 2014 10:07:12 GMT

Here the pretty simple example attached. It illustrates the need in positive
SO_LINGER on server side for non-keep-alive connections.

What is does:
Binds ServerSocket and accepts incoming connections.
When connection is accepted zero SO_LINGER timeout is set.
After that this server reads request headers and sends response headers and
body and closes socket.

What occurs on client-side:
GET request is successfully sent and response headers received.
While consuming the response client will await for FIN packet, but instead it
encounters RST and treats it as connection reset at the middle of body, so
IOException will be thrown by java network layer:

Exception in thread "main" java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:196)
        at java.net.SocketInputStream.read(SocketInputStream.java:122)
        at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
        at org.apache.http.impl.io.SessionInputBufferImpl.read(SessionInputBufferImpl.java:200)
        at org.apache.http.impl.io.IdentityInputStream.read(IdentityInputStream.java:95)
        at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137)
        at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:150)
        at org.apache.http.util.EntityUtils.toByteArray(EntityUtils.java:136)
        at Main.main(Main.java:65)

With positive SO_LINGER response entity will be consumed without any errors.
The more complete example will require to set up the DefaultListeningIOReactor
with zero SO_LINGER, but I see no reason, that it will have different behaviour

Best regards,
Dmitry Potapov

On Wed, Apr 23, 2014 at 09:28:15AM +0000, Oleg Kalnichevski (JIRA) wrote:
>      [ https://issues.apache.org/jira/browse/HTTPCORE-377?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> Oleg Kalnichevski resolved HTTPCORE-377.
> ----------------------------------------
>        Resolution: Fixed
>     Fix Version/s: 4.4-alpha1
> I spent some time trying to figure out the reason for the existing implementation, which
pretty much goes back to the days of HC 3.0
> The existing handling of SO_LINGER appears illogical. It does not prevent abortive connection
close, which can still happen after a positive linger period, but for some reason it it disallows
immediate abortive close.
> I am still not entirely sure whether positive SO_LINGER values make any sense in context
of HTTP, but this is way above my rudimentary understanding of TCP/IP. It is probably just
easier to let users decide.
> Patch committed to SVN trunk. Please review / re-test.
> Oleg
> PS: If you happen to have some bandwidth to investigate whether or not positive SO_LINGER
has its use in HTTP communication, it would be quite welcome. If it does not, it would probably
make sense to deprecate the old parameter and replace it with a simple boolean 'abortive close'
> > Allow to enable SO_LINGER option with zero timeout
> > --------------------------------------------------
> >
> >                 Key: HTTPCORE-377
> >                 URL: https://issues.apache.org/jira/browse/HTTPCORE-377
> >             Project: HttpComponents HttpCore
> >          Issue Type: Improvement
> >          Components: HttpCore, HttpCore NIO
> >    Affects Versions: 4.3.2
> >            Reporter: Dmitry Potapov
> >            Priority: Minor
> >             Fix For: 4.4-alpha1
> >
> >         Attachments: httpcore-enable-linger.patch
> >
> >
> > According to http://docs.oracle.com/javase/8/docs/api/java/net/StandardSocketOptions.html#SO_LINGER
linger option is disabled by default. Currently if SocketConfig.soLinger is set to zero (default
value is -1), then Socket.setSoLinger(false, 0) will be called, so linger will be disabled,
which is undesirable. My suggestion is interpret zero soLinger value as Socket.setSoLinger(true,
> > I understand that this change will break backward compatibility of config interpretation,
but can we have this in 4.4?
> --
> This message was sent by Atlassian JIRA
> (v6.2#6252)
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org

View raw message