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

Oleg Kalnichevski commented on HTTPCORE-718:
--------------------------------------------

[~sajiniekavindya] Your chunking code is _completely_ wrong!!! There are 
_multiple_ HTTP spec violations in your server code. This is how it is supposed 
to be
{code:java}
                int count;
                byte[] buffer = new byte[10453];
                while ((count = payload.read(buffer)) > 0) {
                    System.out.println("server chunk size: " + count);
                    out.print(Integer.toHexString(count)+"\r\n");
                    out.write(buffer, 0, count);
                    out.print("\r\n");
                    out.flush();
                }

                System.out.println("server chunk size: " + 0);
                out.print("0\r\n");
                out.print("\r\n");
                out.flush();
                out.close(); // Flush and close the output stream
                payload.close(); // Close the input stream
                client.close(); // Close the socket itself
{code}
With chunk coding corrected your test app works as expected
{noformat}
Backend server started!
server chunk size: 1410
HTTP/1.1 200 Ok [Content-Type: application/json, Connection: keep-alive, 
Transfer-Encoding: chunked] [Content-Type: application/json,Chunked: true]
server chunk size: 0
Shutting down I/O reactor
https://localhost:7005->HTTP/1.1 200 Ok
Input : [
Input :   {
Input :     "_id": "61b83809ce532e8c96ae5d59",
Input :     "index": 0,
Input :     "guid": "755fd8b2-cb7e-457c-84ca-bdf3041af2e1",
Input :     "isActive": false,
Input :     "balance": "$1,268.32",
Input :     "picture": "http://placehold.it/32x32";,
Input :     "age": 23,
Input :     "eyeColor": "blue",
Input :     "name": "Dina Mcknight",
Input :     "gender": "female",
Input :     "company": "DATACATOR",
Input :     "email": "dinamckni...@datacator.com",
Input :     "phone": "+1 (821) 543-2109",
Input :     "address": "422 Benson Avenue, Fairview, Florida, 1068",
Input :     "about": "Excepteur officia in velit magna do consequat qui magna 
velit. Ex ipsum sunt consectetur exercitation fugiat. Consequat ullamco aute 
exercitation veniam proident. Ex laboris sunt consectetur est consectetur dolor 
ipsum dolor nostrud. Aute elit culpa Lorem non ullamco in elit. Lorem mollit ea 
aliquip reprehenderit nulla commodo non nisi ex aliquip enim anim esse.\r\n",
Input :     "registered": "2015-01-30T01:31:24 -06:-30",
Input :     "latitude": -69.668784,
Input :     "longitude": -159.012416,
Input :     "tags": [
Input :       "aliquip",
Input :       "voluptate",
Input :       "laborum",
Input :       "non",
Input :       "et",
Input :       "ut",
Input :       "irure"
Input :     ],
Input :     "friends": [
Input :       {
Input :         "id": 0,
Input :         "name": "Malinda Curry"
Input :       },
Input :       {
Input :         "id": 1,
Input :         "name": "Brittany Buck"
Input :       },
Input :       {
Input :         "id": 2,
Input :         "name": "Corrine Solomon"
Input :       }
Input :     ],
Input :     "greeting": "Hello, Dina Mcknight! You have 9 unread messages.",
Input :     "favoriteFruit": "apple"
Input :   }
Input : ]
Done
Shutdown
Shutting down the backend server
{noformat}
Oleg

> Getting org.apache.http.ConnectionClosedException after httpcore-nio version 
> upgrade
> ------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-718
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-718
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore NIO
>    Affects Versions: 4.4.15
>         Environment: Java version: 11.0.15.1
> OS: macOS Monterey (Version 12.12.1) 
>            Reporter: Sajinie Kavindya
>            Priority: Major
>         Attachments: HttpNIOTestClient-1.zip
>
>
> We recently migrated to httpcore-nio 4.4.15 and we have been encountering 
> some issues when connecting to an HTTPS Backend that sends chunked responses. 
> The backend behaves in such a manner that when it sends the response, it 
> immediately closes the connection after completion. 
> We have attached a reproducer to this ticket and the behavior is as below.
> When httpcore-nio 4.4.15 is used, the client gets the error:
> {code:java}
> org.apache.http.ConnectionClosedException: Connection closed 
> unexpectedly{code}
> But, when httpcore-nio 4.4.5 is used, the client receives the complete 
> response, which was sent from the backend.
> We further checked on the following versions and the observations are as 
> below. 
>  * httpcore-nio 4.4.10 - receives the complete response
>  * httpcore-nio 4.4.11 - receives org.apache.http.ConnectionClosedException
> In order to replicate the issue, we did a few changes to the 
> consumeContent(final ContentDecoder decoder) method inside the 
> SimpleInputBuffer class. You may find the changes in the attached source code.
> In order to test the behavior, please run the Main class: 
> “{*}TestChunkedBackend{*}”.
> Tested environment:
>  * Java version: 11.0.15.1
>  * OS: macOS Monterey (Version 12.12.1) 
> A similar issue can be found here 
> [https://issues.apache.org/jira/browse/HTTPCORE-706|http://example.com]
> Thanks & Regards,
> Sajinie
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to