[Azure.Core] Disable TCP_FAST_OPEN to avoid a WinHttp issue (#4530)

* Disable TCP_FAST_OPEN to avoid a WinHttp issue

* Add Changelog entry
This commit is contained in:
Rick Winter 2023-04-07 15:52:58 -07:00 коммит произвёл GitHub
Родитель b9e09760e5
Коммит 369f86ce6d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 18 добавлений и 13 удалений

Просмотреть файл

@ -35,6 +35,7 @@ Thank you to our developer community members who helped to make Azure Core bette
- [[#4213]](https://github.com/Azure/azure-sdk-for-cpp/issues/4213) Fixed a bug where `Host` request header is not set for non-default port (80, 443). - [[#4213]](https://github.com/Azure/azure-sdk-for-cpp/issues/4213) Fixed a bug where `Host` request header is not set for non-default port (80, 443).
- [[#4443]](https://github.com/Azure/azure-sdk-for-cpp/issues/4443) Fixed potentially high CPU usage on Windows. - [[#4443]](https://github.com/Azure/azure-sdk-for-cpp/issues/4443) Fixed potentially high CPU usage on Windows.
- [[#4490]](https://github.com/Azure/azure-sdk-for-cpp/issues/4490) Fixed WinHTTP memory leak during failed requests.
### Other Changes ### Other Changes

Просмотреть файл

@ -554,10 +554,10 @@ namespace Azure { namespace Core { namespace Http { namespace _detail {
* multiple times based on the state of the TLS connection. * multiple times based on the state of the TLS connection.
* *
* Special consideration for the WINHTTP_CALLBACK_STATUS_SENDING_REQUEST - this callback is * Special consideration for the WINHTTP_CALLBACK_STATUS_SENDING_REQUEST - this callback is
* called during the TLS connection - if a TLS root certificate is configured, we verify that the * called during the TLS connection - if a TLS root certificate is configured, we verify that
* certificate chain sent from the server contains the certificate the HTTP client was configured * the certificate chain sent from the server contains the certificate the HTTP client was
* with. If it is, we accept the connection, if it is not, we abort the connection, closing the * configured with. If it is, we accept the connection, if it is not, we abort the connection,
* incoming request handle. * closing the incoming request handle.
*/ */
void WinHttpAction::OnHttpStatusOperation( void WinHttpAction::OnHttpStatusOperation(
HINTERNET hInternet, HINTERNET hInternet,
@ -584,8 +584,8 @@ namespace Azure { namespace Core { namespace Http { namespace _detail {
} }
else if (internetStatus == WINHTTP_CALLBACK_STATUS_SENDING_REQUEST) else if (internetStatus == WINHTTP_CALLBACK_STATUS_SENDING_REQUEST)
{ {
// We will only set the Status callback if a root certificate has been set. There is no action // We will only set the Status callback if a root certificate has been set. There is no
// which needs to be completed for this notification. // action which needs to be completed for this notification.
m_httpRequest->HandleExpectedTlsRootCertificates(hInternet); m_httpRequest->HandleExpectedTlsRootCertificates(hInternet);
} }
else if (internetStatus == m_expectedStatus) else if (internetStatus == m_expectedStatus)
@ -605,8 +605,8 @@ namespace Azure { namespace Core { namespace Http { namespace _detail {
CompleteAction(); CompleteAction();
break; break;
case WINHTTP_CALLBACK_STATUS_READ_COMPLETE: case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
// A WinHttpReadData call has completed. Complete the current action, including the amount // A WinHttpReadData call has completed. Complete the current action, including the
// of data read. // amount of data read.
CompleteActionWithData(statusInformationLength); CompleteActionWithData(statusInformationLength);
break; break;
case WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING: case WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING:
@ -700,11 +700,15 @@ Azure::Core::_internal::UniqueHandle<HINTERNET> WinHttpTransport::CreateSessionH
GetErrorAndThrow("Error while getting a session handle."); GetErrorAndThrow("Error while getting a session handle.");
} }
// These options are only available starting from Windows 10 Version 2004, starting 06/09/2020. // These options are only available starting from Windows 10 Version 2004, starting 06/09/2020.
// These are primarily round trip time (RTT) performance optimizations, and hence if they don't get // These are primarily round trip time (RTT) performance optimizations, and hence if they don't
// set successfully, we shouldn't fail the request and continue as if the options don't exist. // get set successfully, we shouldn't fail the request and continue as if the options don't exist.
// Therefore, we just ignore the error and move on. // Therefore, we just ignore the error and move on.
#ifdef WINHTTP_OPTION_TCP_FAST_OPEN
// TCP_FAST_OPEN has a bug when the DNS resolution fails which can result
// in a leak. Until that issue is fixed we've disable this option.
#if defined(WINHTTP_OPTION_TCP_FAST_OPEN) && FALSE
BOOL tcp_fast_open = TRUE; BOOL tcp_fast_open = TRUE;
WinHttpSetOption( WinHttpSetOption(
sessionHandle.get(), WINHTTP_OPTION_TCP_FAST_OPEN, &tcp_fast_open, sizeof(tcp_fast_open)); sessionHandle.get(), WINHTTP_OPTION_TCP_FAST_OPEN, &tcp_fast_open, sizeof(tcp_fast_open));