Support for Socket Write and Read Timeout Settings in CRT
- Dominant language
- C++
- Stars
- 91
- Forks
- 87
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 3
Description
### Describe the feature
The current implementation of the CRT's [SocketOptions](https://github.com/awslabs/aws-crt-cpp/blob/main/include/aws/crt/io/SocketOptions.h) does not provide support for configuring read and write timeouts for non-blocking socket operations. While traditional blocking sockets can leverage options like SO_RCVTIMEO (receive timeout) and SO_SNDTIMEO (send timeout) to set timeouts for read and write operations, CRT operates in a non-blocking mode, requiring custom mechanisms to achieve similar timeout behavior.
### Use Case
We are migrating our Java SDK clients to the CRT-based HTTP client. The existing SDK supports configurable socket-level timeouts that ensure timely error handling and retries if:
1. A write operation cannot be completed within the write timeout (e.g., sending a request).
1. A read operation cannot be completed within the read timeout (e.g., receiving a response after a request is sent).
To maintain compatibility and ensure robust error handling in non-blocking CRT, we need equivalent timeout settings that close the connection when timeouts are exceeded.
### Proposed Solution
1. Extend the SocketOptions Interface:
Add the following properties to SocketOptions to support timeout settings:
* `readTimeoutMs`: The maximum time (in milliseconds) allowed to complete a read operation.
* `writeTimeoutMs`: The maximum time (in milliseconds) allowed to complete a write operation.
2. Introduce Timeout Handlers:
Implement dedicated read timeout handlers and write timeout handlers that monitor the progress of non-blocking operations.
These handlers should enforce timeouts:
Read Timeout Handler: Monitors the time elapsed since a read operation is triggered. If no data is received within the readTimeoutMs, raise a timeout exception.
Write Timeout Handler: Monitors the time elapsed since the last write operation. If data cannot be sent within the writeTimeoutMs, raise a timeout exception.
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
Contributor guide
Research direction
Start with include/aws/crt/io/SocketOptions.h and trace the CRT's non-blocking socket read and write operation paths. Determine where readTimeoutMs and writeTimeoutMs belong and how timeout handlers should close the connection and report timeout errors; done means both settings enforce the requested limits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100