rbeeli / websocketclient-cpp

A transport-agnostic, high-performance, header-only C++23 WebSocket client library with minimal dependencies.
MIT License
1 stars 1 forks source link

Handling EINTR errors for I/O operations #2

Closed MeanSquaredError closed 1 month ago

MeanSquaredError commented 1 month ago

Hi,

After looking into the library's source code it seems that the library does not handle EINTR errors that happen when:

If these conditions are met, then the I/O operation fails with an EINTR error code.

This problem can happen easily when the program has established a handler for SIGINT in order to shutdown gracefully or re-read its configuration when it receives the signal.

The usual workaround for this issue is just retrying the I/O operation when it returns EINTR. In pseudocode it looks like this:

do {
    auto error_code = read (...);
} while (error_code == EINTR);
rbeeli commented 1 month ago

Hi,

Where did you check, and which socket client implementation did you consider?

Both built-in synchronous socket clients TcpSocket and OpenSslSocket have a check for EINTR:

https://github.com/rbeeli/websocketclient-cpp/blob/main/include/ws_client/transport/builtin/OpenSslSocket.hpp#L257

https://github.com/rbeeli/websocketclient-cpp/blob/main/include/ws_client/transport/builtin/TcpSocket.hpp#L248

If you experience a specific error or unexpected result, please provide a MWE.

MeanSquaredError commented 1 month ago

Indeed I did not notice that tcp/ssl reads and writes have the check for EINTR. However the connect() and SSL_connect() calls are lacking the checks for EINTR and they can fail with EINTR too.

rbeeli commented 1 month ago

You are right, those function slipped my attention regarding EINTR, will look into it next week. Thanks.

rbeeli commented 1 month ago

connect and SSL_connect are now checked for EINTR in TcpSocket and OpenSslSocket.

MeanSquaredError commented 4 weeks ago

Thank you for fixing that!