Subject: | Net::HTTP::Methods::my_readline fails to read last chunk for keepalive connections |
https://github.com/libwww-perl/net-http/commit/8311cd11544f59100d1f135e63007b8f3ded50d9?diff=unified has introduced the following problem:
Suppose we have UA with keep-alive enabled and server sends us exactly 1024 bytes of data that we receive as one sysread call. Once this happens `last if $bytes_read < 1024;` would be false and loop on line 276 will repeat. But this time socket is empty, so EAGAIN would be returned and code will jump to 'READ' label. This means that it would call 'can_read' and code will call 'select' on a socket. Now, since we have received all data for this request we are getting no more data. But since this connection has keep-alive enabled server will not close this connection. This means select will get stuck forever.
This wasn't the problem before patch linked above got introduced because 'my_readline' function was reading only up to a complete line of data (as name suggests) - and http protocol makes sure that last character of the message is new line.
Unfortunately https://rt.cpan.org/Public/Bug/Display.html?id=104122 (for which comment above was introduced) doesn't really explain why exactly it wanted eagerly my_readline to read all the data from the socket instead of just reading as much as needed to get a complete line. That bug doesn't explain in what case original implementation had caused any problems.
But current implementation is clearly causing problems in case outlined in first paragraph.
Would it be possible to revert commit mentioned above to fix keep-alive behaviour and possible apply some other fix to address real issue for SSL sockets?
Thanks!