Skip to content

HttpClient Proposal - add Connect and Socket timeouts #11594

@starovernet

Description

@starovernet

Problem

We are writing financial services and have to be compliant with requirements, which force us to have different timeout values for TLS handshake and after connect till getting response. Quote from requirements: "Read timeouts occur while waiting on a transaction response after the connection has been established and the message is sent to the recipient. Connection timeouts occur while
making the initial connection (i.e. completing the TCP/IP connection and TLS handshake).".

Link to spec:
https://www.emvco.com/terms-of-use/?u=/wp-content/uploads/documents/EMVCo_3DS_Spec_v220_122018.pdf

Current workaround

We can start Connection timeout before call SendAsync, then use ServerCertValidationCallback to stop it and start new timeout until receive response. Problem, that ServerCertValidationCallback occurs only for new connections, and if we reuse connection, we don't need to set it. In this case we can't reuse connection and need to set ConnectionClose property, which is bad for performance.

Proposed Solution

There is many ways to handle it. For example.

  • Add 2 properties, like in Apache HttpClient 4
public class HttpClient : HttpMessageInvoker
{
    ...
    public TimeSpan ConnectTimeout { get; set; } 
    public TimeSpan SocketTimeout { get; set; }
    ...
}
  • Add new Event to HttpClient class
public event EventHandler Connected; 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions