awslabs / aws-crt-swift

Apache License 2.0
15 stars 14 forks source link

Specialize HTTP client for Apple platform to fix the connection issue while running in the background #211

Open waahm7 opened 10 months ago

waahm7 commented 10 months ago

Describe the feature

Follow up to https://github.com/awslabs/aws-sdk-swift/issues/1086 Enable the CRT HTTP client to continue handling events in the background on Apple platform clients.

The standard event handling mechanism used by the CRT HTTP client (kqueue) is not fully supported on Apple platforms (i.e. native iOS/iPadOS, tvOS, macOS applications). Using the CRT HTTP client as-is on Apple platforms will result in broken connections if the application is not in the active state for the entire duration of the connection; this is a severe limitation for most use cases, especially for mobile devices where connection speeds are limited and users are restricted to one foreground app at a time.

To remedy this limitation, an alternative event handling mechanism ("dispatch queues") must be used on Apple platforms, since dispatch queues continue to handle events as expected throughout the application lifecycle. The CRT HTTP client will be modified to use the correct event handling mechanism when building for the platforms that require it.

Use Case

To enable efficient, background HTTP communications via the AWS SDK for Swift.

Proposed Solution

Use Apple platform-native event handling on Apple platforms, instead of CRT's current event handling which is based on POSIX threads.

Other Information

No response

Acknowledgements

waahm7 commented 7 months ago

blocked by https://github.com/awslabs/aws-sdk-swift/issues/1307

sichanyoo commented 4 months ago

For macOS:

Tested using a simple dummy macOS application that uploads a 5GB file to S3 using CRT HTTP client. When app is unfocused or minimized, it uploads the file successfully as expected. When mac is put to sleep, it fails to upload the file as expected. Conclusion: CRT HTTP client works fine on macOS.

However, for the scenario where mac is put to sleep, the application terminated unexpectedly. A follow-up ticket is created for this bug, and is getting worked on now.

*Follow-up ticket for the bug found: https://github.com/awslabs/aws-sdk-swift/issues/1474

sichanyoo commented 4 months ago

Closed https://github.com/awslabs/aws-sdk-swift/issues/1307 as it's confirmed CRT HTTP client works as expected on macOS when the app is unfocused / minimized (expected success) and when app is suspended by mac being put to sleep (expected failure).