orca-zhang / influxdb-cpp

💜 C++ client for InfluxDB.
MIT License
163 stars 83 forks source link

Program hangs on recv() #52

Closed WitSzoniec closed 3 days ago

WitSzoniec commented 5 days ago

Hello,

I had an unusual situation where the http request was sent without any problem, but in the meantime connection to the data base was lost for a while and program stuck on getting a response.

(gdb) thread 9
[Switching to thread 9 (Thread 0x7f6c967fc700 (LWP 2040807))]
#0  0x00007f6ca8124d36 in recv () from /lib64/libpthread.so.0
(gdb) bt
#0  0x00007f6ca8124d36 in recv () from /lib64/libpthread.so.0
#1  0x00000000005d5b51 in influxdb_cpp::detail::inner::http_request (method=method@entry=0xd5b070 "POST", uri=uri@entry=0xe83e6d "write", querystring="",
    body="XXX", si=..., resp=resp@entry=0x7f6c967fbd68, timeout_sec=10)
    at /opt/rh/devtoolset-11/root/usr/include/c++/11/bits/basic_string.h:4110

In the library, the timeout is set for send operation (influxdb.hpp:218):

if(setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char*> (&timeout), sizeof(timeout)) < 0) return -2;

but not for the receive operation (SO_RCVTIMEO flag) - root cause.

Proposed changes to solve this issue: https://github.com/orca-zhang/influxdb-cpp/pull/53

Thanks :)

orca-zhang commented 3 days ago

Thank you for your contribution.

WitSzoniec commented 3 days ago

No problem :) Thank you for the lib :)