Author Topic: HTTP Internal Retry after Lost Connection Discovered  (Read 883 times)

Chilkat

  • Administrator
  • Full Member
  • *****
  • Posts: 103
  • Karma: +7/-0
    • View Profile
HTTP Internal Retry after Lost Connection Discovered
« on: November 29, 2017, 09:05:43 AM »
We are having issues where the remote host is forcibly closing our connection and ChilkatHttpRequest is then retrying (retryAfterLostConnectionDiscovered2).

We need to be able to stop this retry happening, or for a predefined period (we need to exceed 4 seconds before a retry), as the remote system cannot cope (itís not a Firewall issue, the host has a poorly designed processor).

Please let me know how this can be implemented.

Chilkat

  • Administrator
  • Full Member
  • *****
  • Posts: 103
  • Karma: +7/-0
    • View Profile
Re: HTTP Internal Retry after Lost Connection Discovered
« Reply #1 on: November 29, 2017, 09:22:23 AM »
The Chilkat.Http (or CkHttp) class caches open connections.   For example, if your app calls Http.QuickGetStr("https://www.chilkatsoft.com"), Chilkat will by-default add a "Connection: keep-alive" header.  (You can remove this header by setting the Http.Connection property equal to the empty string.)  If the server's response includes a "Connection: close" header, then Chilkat knows the server will be closing the connection after the response is sent.  Thus the open connection won't be cached.   

A cached connection is good for performance.  If, for example, you are sending 10 GET requests in a row, then all can occur on the same connection.

Here's what's happening in your case.  Imagine you send a request and the open connection is cached because the server did not include a "Connection: close" in the response header.  Then your app doesn't send another request for quite some time, but meanwhile the server closes its connection due to inactivity.  We now have a half-closed connection, that is not yet discovered by Chilkat, because Chilkat hasn't yet tried to do anything (read/write) on the connection.   Your app then sends the next request, the cached connection is found, and we try to write to it -- but that's when it's discovered that the connection was previously closed by the server.  No problem, we'll just open a new connection and send the request. 

If you don't want the connection cached, you can set the Http.Connection property = "".    Also, you can call Http.CloseAllConnections to forcibly close any open/cached connections prior to the next HTTP request.