For some time, we were having random errors on Solaris with proton-c where we would get a transport error "proton:io connect: Error 0". We were finally able to reproduce it in a multi-threading environment. It turns out some C/C++ system calls such as opening sockets will set the value of "errno" and some parts of proton-c code you rely on the value of errno to determine if the operation was successful or not.
The issue is that errno is not thread safe and as a consequence if by the time Thread A was checking the value of errno, Thread B has set it to something else, the check will fail.
We resolved it by compiling Proton with "-D_REENTRANT" which makes errno thread local variable.
Please note we only got this error on Solaris because on Linux setting "-lpthread" implies "-D_REENTRANT flag" according to stackoverflow.
Do you think this flag could be set by default in the CMakeList of proton to avoid others having the same issue?
#if defined(_REENTRANT) || defined(_TS_ERRNO) || _POSIX_C_SOURCE - 0 >= 199506L
extern int *___errno();
#define errno (*(___errno()))
extern int errno;
/* ANSI C++ requires that errno be a macro */
#if __cplusplus >= 199711L
#define errno errno
#endif /* defined(_REENTRANT) || defined(_TS_ERRNO) */
PS: The code is still the same on 0.14.0. So the error could happen there as well I guess.
: https://github.com/apache/qpid-proton/blob/0.12.2/proton-c/src/posix/io.c (line 187-188)