Граф коммитов

674 Коммитов

Автор SHA1 Сообщение Дата
John L 48a8cc3636
Fix crash caused by race condition in WinHttp teardown (#788)
Upon receiving a suspend event, the WinHttp provider will automatically tear down any active WebSocket connections. Depending on the current state of the connection, the suspend handler will either call WinHttpWebSocketClose followed by WinHttpCloseHandle, or just call WinHttpCloseHandle directly. If we receive a WinHttp disconnect callback at the same time, the disconnect handler will call WinHttpCloseHandle. This leads to race condition between the two handlers:

If the suspend handler runs first and determines that it needs to call WinHttpWebSocketClose (because at that point we believe the WebSocket is still connected) and then the disconnect handler runs and calls WinHttpCloseHandle BEFORE the suspend handler actually calls WinHttpWebSocketClose, the WinHttp handle may be in an invalid state when WebSocketClose finally gets called, leading to a crash.

The fix here involves a couple things. First, I updated the suspend handler to forego the call to WinHttpWebSocketClose altogether. This means that during suspend the WebSocket won't be torn down gracefully, but it greatly simplifies the LHC teardown process. Second, there is some additional logic needed to make sure that LHC still raises a disconnected event to clients during suspend, as the flow will change slightly with the removal of the WinHttpWebSocketClose call.

This change also contains a fix for a debug assert due to buffer size in FormatTrace
2023-11-14 15:35:00 -08:00
tculotta ffe0ee95aa
fix crash when large buffers are sent through HCTrace (#787) 2023-11-13 10:30:40 -08:00
Raul Gomez Rodriguez 3df5588fc0
GZIP Compression support for Apple (#786)
* Adding Zlib from Source to Apple LHC

* Adding Compression API to exp files

* Adding ifdef to pch_common.h

* Subtle bug in new build guards

* Replacing iOS and MAC build guards for HC_PLATFORM_IS_APPLE

* Isolating Zlib warnings to specific files

* Fixing Targets with corresponding compiler flags

* Excluding one least warning treated as error

---------

Co-authored-by: raulalbertog <raulalbertog@microsoft.com>
2023-11-09 17:17:07 -06:00
Sebastian Perez-Delgado 19c45d78f7
libcurl build update (#783)
* change curl flags
---------

Co-authored-by: Sahil Ashar <saashar@microsoft.com>
2023-10-10 17:22:14 -07:00
Jason Sandlin 18d2a68c62
Various minor fixes to LHC Linux CMake (#781)
* Various minor fixes to LHC Linux CMake

* PR feedback

* PR feedback

* Fixing Android cmake paths'
2023-10-10 13:39:44 -07:00
Raul Gomez Rodriguez 8472e3210e
Adding ZLIB to cgimanifest.json and ThirdPartyNotices.txt (#782)
* Adding ZLIB to cgmanifest.json

* Adding ZLIB License to ThirdPartyNotices.txt

* Updating openssl commit hash in cgmanifest.json
2023-10-06 17:39:32 -06:00
John L 1d69edfa25
Update OpenSSL build prop name (#780) 2023-10-03 17:05:03 -07:00
John L b8071bdc6f
Add and document build customization options (#779)
* Add and document build customization to exclude Zlib and OpenSSL dependencies
2023-10-03 14:21:37 -07:00
Raul Gomez Rodriguez a21681e91d
Expanding compression to Switch platform (#778)
* Including Switch on if guards

* Fix missing guard for Switch

---------

Co-authored-by: Raul Gomez Rodriguez <raulalbertog@microsoft.com>
2023-09-28 12:48:05 -06:00
rgomez391 149bfeb9de
Task 45629821: Add support for GZIP Compression (#774)
* Initial changes

* Fix unknown override specifier errors

* GZIP Integration with Win32 and GDK

* Adding support for 2019

* Restoring Win32 Sample app

* Removing unnecessary include

* Excluding ZLib on props files

* Managing ZLib source compilation in props files

* Fixing variable redeclaration

* Addressing PR Feedback Pt1

* Pointing to v1.3 commit

* Addressing PR Feedback pt2

* Enabling compression through read body callback

* Addressing PR Feedback

* Minor changes

* Addressing PR Feedback

* Removing extra buffer in compress function

* Minor mistake in compression header

* Removing unnecessary buffer when reading body

* Moving compression from Common to HTTP

* Removing loop and reading whole body at once

---------

Co-authored-by: Raul Gomez Rodriguez <raulalbertog@microsoft.com>
2023-09-07 22:48:29 -06:00
Alonso Mondal e04e978566
Updating GDK BWOI Props to support VS2022 (#777)
adding properties for GDK BWOI with VS2022
2023-08-25 15:15:52 -06:00
John L 0b7a07d2b3
GDK build fix
Allow override of SpectreMitigation property since enabling it breaks XSAPI's GDK BWOI builds
2023-08-10 12:56:40 -07:00
John L 81cba927aa
Fixes to the GDK props file (#775)
* Import GDK bwoi props file prior to using VCTargetsPath as that gets changed when 'GDKUseBWOI' is set
* Define _DEBUG macro for debug builds to avoid linker errors when building XSAPI
2023-08-09 11:48:37 -07:00
tculotta 670f91ce4b
Task 45828333: Move existing ETW tracing into LHC (#772) 2023-08-04 11:17:52 -07:00
Luca Beltrami cc017c12da
Add missing macro to libHttpClient.props (#773) 2023-08-03 14:13:10 -07:00
Jason Sandlin 52f0ecbf48
Add header when building for other platforms (#771) 2023-08-03 04:54:47 -07:00
Nassos Terzakis 7e66157fd8
Skip defining vsprintf_s for PlayStation (#770) 2023-07-24 12:50:51 -07:00
John L a6febd0827
Internal PAL improvements + project refactoring to better support additional platforms (#768)
At a high level, the goal of these changes is to restructure the code and project files to better allow for extending libHttpClient to new platforms, including platforms that require an NDA and need to be maintained outside of the public github repository.  Specific changes in this pull request include:
* Added IHttpProvider and IWebSocketProvider interfaces which platform specific implementations of HTTP and WebSockets must implement. 
* Added PlatformComponents struct and PlatformInitialize method which each platform must implement.  Those implementations can easily exist outside the primary github repository without modification to existing source.
* Removal of the HC_PERFORM_ENV class which acted as a context object for all of the in-box HTTP and WebSocket providers. It had gotten extremely messy and required updating for new platforms.  This was replaced by the NetworkState class, which does a lot of the same things, but it contains no platform specific code.  Rather than having hard-coded HTTP and WebSocket hooks for each platform, it is initialized with an IHttpProvider and IWebSocketProvider during HCInitialize. 
* Refactoring of props files in the /Build directory. A libHttpClient.[platform].props file was added for each supported platform. These props files define the platform specific default build configuration and will be imported by each project targeting that platform.
* Refactoring visual studio project files and removal of the CMake + ProjectFileProcessor utility that was used to generate the project files.  That system has been replaced by a much more modular build system which breaks source files required for multiple projects into .vcxitems projects. The .vcxproj files end up being very minimal, referencing the appropriate .props files and .vcxitems projects based on the platform they target.
* Some minor cleanup and code refactoring including addition of internal types.h header and dependency on std::optional in Result<T> class
* Dropped support for the XDK platform as well as visual studio 2015.  Additionally the visual studio 2017 .sln was removed, but the projects building with platform toolset 141 were maintained and can still be used if needed.
2023-07-20 11:44:11 -07:00
Luca Beltrami d9de7ed4e0
Import changes from OS repo. (#763)
* Import changes from OS repo.

Almost all the changes are about fixing code analysis warnings

* Add missing SAL annotation to pal.h
2023-07-06 16:22:56 -07:00
John L 53dc58fce2
Fix bug in CurlMulti (#762)
CurlMulti creates a composite work queue and schedules work to that queue as long as there are outstanding HTTP requests.  During cleanup, CurlMulti will terminate its queue, effectively cancelling all ongoing requests.  However, if there are no ongoing requests at the time of cleanup, there is no guarantee that the client will still be dispatching the queue, which is required to fully terminate a queue.  To fix this I've done two things:
1. Only terminate the queue if there are ongoing requests. If there are no ongoing requests, we're guaranteed to have no remaining callbacks pending on the queue, so termination is unnecessary.
2. When terminating the queue, don't await a queue terminated callback.  This avoids a potential race condition where the client stops dispatching the queue after they've gotten a completion callback for the final HTTP request but before they've dispatched the queue terminated callback.

I also added some additional verbose logging to help diagnose future cleanup issues.
2023-07-06 12:58:24 -07:00
Sebastian Perez-Delgado 38cc8ed178
LibHC linux build curl using libssl in repo submodule (#752)
* change build order

* change curl flags

* change pipeline to reflect dependency changes

* revised bash scripts

* fix white space nit

* restructure build scripts and pipeline

---------

Co-authored-by: Sahil Ashar <saashar@microsoft.com>
2023-06-22 11:24:14 -07:00
John L 1c8386866f
Fix leak in WebSocket (#747) 2023-06-05 13:47:02 -07:00
Sebastian Perez-Delgado 641939771d
Update libHttpClient_Linux.bash (#742) 2023-05-26 17:55:45 -07:00
Matt VanderKolk 0d3add41d6
Updating Android NDK version to 25.1.8937393 (#743)
* Updating Android NDK to 25.1.8937393

* Updating libcrypto and libssl as well
2023-05-26 10:47:19 -07:00
Sebastian Perez-Delgado 38cd3211c0
removing ninja build system (#741) 2023-05-19 15:24:07 -07:00
Sebastian Perez-Delgado 501c45b963
Update NOTICE.txt (#739)
Create new notice to reflect the new pipeline
2023-05-18 15:02:58 -07:00
Sebastian Perez-Delgado cf825b3782
Add build pipeline and change LibHC linux to build with CMake (#738)
Created CMake files for LibHC Linux

Created Bash Script to help compile LibHC Linux


Removed WSL VCXProj files
2023-05-18 13:50:51 -07:00
Luca Beltrami 69eb79629d
Fix crash when last websocket handle is closed while sending a message (#736)
* fix

* Fix build

* Fix take 2

* Stop owning shared objects by unique ptr
2023-04-11 18:50:32 -07:00
Sebastian Perez-Delgado 44aa6f5d47
Fix for XcURL and cURL behavior differences. (#733)
* Add Linux build files and configure files to support LibHttpClient Linux

* resolving comments

Removed extern structs in .h file and moved them up where they were in pch_common to ensure they are defined properly

* added templates

* Update x509_cert_utilities.hpp

* Update x509_cert_utilities.hpp

change check to something defined by us

* Update x509_cert_utilities.hpp

fix error in pipeline where there are errors of an unused function.

* Update x509_cert_utilities.hpp

use elif and corrected to use else

* Update CurlEasyRequest.cpp

Fix to handle behavioral differences with cURL and XcURL

* Update CurlEasyRequest.cpp

have this be a fix/workaround for xCurl

---------

Co-authored-by: SebastianPD-XB <sebastianp@microsoft.com>
2023-03-16 12:56:53 -07:00
Sebastian Perez-Delgado 0c1ac487ea
LibHttpClient Linux: Add Linux build files and configure files to support LibHC Linux. (#732)
* Add Linux build files and configure files to support LibHttpClient Linux

* resolving comments

Removed extern structs in .h file and moved them up where they were in pch_common to ensure they are defined properly

* added templates

* Update x509_cert_utilities.hpp

* Update x509_cert_utilities.hpp

change check to something defined by us

* Update x509_cert_utilities.hpp

fix error in pipeline where there are errors of an unused function.

* Update x509_cert_utilities.hpp

use elif and corrected to use else

---------

Co-authored-by: SebastianPD-XB <sebastianp@microsoft.com>
2023-03-10 16:45:35 -08:00
John L 798f603084
Fix a few unhooked allocations (#730)
When creating a std::shared_ptr<> from a raw pointer, we need to pass in both a custom deleter and allocator. Though the object itself is already allocated, std::shared_ptr<> allocates some internal data on top of that.

More details here: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr.
2023-01-20 14:54:00 -08:00
John L 41e4e73cc1
Fixes in WinHttp WebSocket stack (#726)
This PR fixes a few different bugs in the WinHttp WebSocket stack:

1) The most severe bug is related to situations where WinHttpSendRequest fails synchronously.  This can happen for a variety of reasons, though it does not seem to be consistent.  According to msdn docs, (https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpsendrequest) "even when WinHTTP is used in asynchronous mode, that is, when WINHTTP_FLAG_ASYNC has been set in [WinHttpOpen](https://learn.microsoft.com/en-us/windows/desktop/api/winhttp/nf-winhttp-winhttpopen), this function can operate either synchronously or asynchronously."  In our code, if the WinHttpSendRequest call failed synchronously, we'd clean up the WinHttp callback context which we still expected to exist to handle other WinHttp events (i.e. WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) resulting in us accessing an invalid pointer.  The fix is to release ownership of the callback context after WinHttpSetStatusCallback (rather than after WinHttpSendRequest).

2) The second bug that was in some error paths of HCWebSocketConnectAsync, the WinHttpCloseHandle never happens, nor is our WinHttp callback context ever cleaned up.  The fix is to call StartWinHttpClose from WinHttpConnection::complete_task if the WebSocket Connect has fails.  In cases where it succeeds, cleanup works correctly but doesn't take place until the WebSocket is later disconnected.  This bug doesn't result in any crash, but does leak WinHttp handles and associated LHC context in some cases.

3) The final bug is that in some cases the client's WebSocket disconnect handler may be invoked multiple times.  In some cases WinHttp can raise multiple error events (WINHTTP_CALLBACK_STATUS_REQUEST_ERROR), but we should only notify the client of a disconnect once.  The fix is to add a flag to track whether we've already called the disconnect handler, and ignore subsequent WinHttp errors.  This also doesn't cause any crashes, but could cause issues depending on how clients handle the disconnect event being fired multiple times.
2022-12-02 08:57:25 -08:00
Jamie Magee 7f502aa60d
Add `$schema` to `cgmanifest.json` (#713)
Co-authored-by: Jamie Magee <jamie.magee@microsoft.com>
Co-authored-by: Matt VanderKolk <mava@microsoft.com>
Co-authored-by: Sahil Ashar <saashar@microsoft.com>
2022-10-28 15:47:49 -07:00
Nathan Iskandar 09713544c6
include stdarg.h in trace.h to fix ios build (#725)
* include stdarg.h in trace.h to fix ios build

* include order

* add HCTraceImplMessage_v to exports
2022-10-25 12:15:37 -07:00
Jason Sandlin a8db24d1d0
Adding HC_PLATFORM_GRTS which is used internally by XAL in some places (#724) 2022-10-24 15:10:08 -07:00
Nathan Iskandar 30118d6867
va_list version of HCTraceImplMessage for extensibility (#723) 2022-10-17 14:58:03 -07:00
Matt VanderKolk 559dacf3bb
Adding '#if !HC_NOWEBSOCKETS' to new websockets file. (#722) 2022-10-14 12:17:27 -07:00
Matt VanderKolk 691441af51
Ignoring deprecated declarations warnings for external asio code. (#721)
Co-authored-by: Jason Sandlin <jasonsa@microsoft.com>
2022-10-13 09:46:02 -07:00
Jason Sandlin e6a5cd2bc6
Improving Retry-After API doc (#720)
* Improving Retry-After API doc

* PR
2022-10-11 15:55:59 -07:00
Sahil Ashar 75dc4785c9
Update Android WebSocket Binary Messages (#719) 2022-10-06 11:15:08 -07:00
David Westen 53d216267d
Use okhttp for websockets on android (#714)
* Use okhttp for websockets on android

* empty commit to re-trigger build pipelines

Co-authored-by: Jason Sandlin <jasonsa@microsoft.com>
Co-authored-by: Sahil <saashar@microsoft.com>
2022-09-19 13:48:26 -05:00
Jason Sandlin b8e335836e
Switching libHttpClient logs to show up at info level instead of verbose (#716) 2022-09-14 16:58:59 -07:00
Jason Sandlin 13ed3a2bea
Enable verbose logs on release builds (#715) 2022-09-13 18:30:11 -07:00
Jason Sandlin 733036e038
Adding comment wrt xcurl (#711) 2022-08-10 00:44:45 -07:00
Matt VanderKolk 236c7c8246
Re-classifying NO_NETWORK to be only UnknownHostException on Android (#709)
* Re-classifying NO_NETWORK to be only UnknownHostException
At some point recently various socket exceptions started getting classified as "isNoNetworkFailure". While this was intended to be helpful classification, the resulting behavior is that on a socket exception, retry logic will not get engaged. This is because retry logic does not attempt to retry if there is no network in order to save from repeatedly waiting when there isn't a reason to wait. This behavior change was not good or intended so I am reverting it.
2022-07-28 14:36:39 -07:00
Nathan Iskandar d81df0a775
Add HCMockCallCloseHandle and HCMockCallDuplicate handle to exports files (#710) 2022-07-28 13:44:20 -07:00
Nathan Iskandar 3468ca2513
Add HCMockCallCloseHandle (#708)
* add HCMockCallCloseHandle

* add HCMockCallDuplicateHandle for completeness
2022-07-27 12:16:55 -07:00
Maxim Ivanov 529df0581d
Fix Android build on Linux hosts (#705)
Co-authored-by: Jason Sandlin <jasonsa@microsoft.com>
2022-07-21 15:53:27 -07:00
Maxim Ivanov f240b2e2dc
Stop including same file twice under different paths (#707) 2022-07-21 15:52:54 -07:00
Jason Sandlin d075554d38
Adding support for /Zc:strictStrings (#706) 2022-07-20 15:52:33 -07:00