You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Adel Boutros <ad...@live.com> on 2016/08/29 07:32:46 UTC
[Qpid Proton 0.12.2] errno not thread-safe on Solaris
Hello,
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[1].
The issue is that errno is not thread safe[2] 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[2].
Do you think this flag could be set by default in the CMakeList of proton to avoid others having the same issue?
On Solaris:
/usr/include/errno.h
#if defined(_REENTRANT) || defined(_TS_ERRNO) || _POSIX_C_SOURCE - 0 >= 199506L
extern int *___errno();
#define errno (*(___errno()))
#else
extern int errno;
/* ANSI C++ requires that errno be a macro */
#if __cplusplus >= 199711L
#define errno errno
#endif
#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.
Regards,
Adel
[1]: https://github.com/apache/qpid-proton/blob/0.12.2/proton-c/src/posix/io.c (line 187-188)
[2]: http://stackoverflow.com/questions/1694164/is-errno-thread-safe
[3]: http://stackoverflow.com/questions/875789/gcc-do-i-need-d-reentrant-with-pthreads
Re: [Qpid Proton 0.12.2] errno not thread-safe on Solaris
Posted by Andrew Stitcher <as...@redhat.com>.
On Mon, 2016-08-29 at 17:07 +0200, Adel Boutros wrote:
> Hello Andrew,
>
> I wanted to make sure it was a bug before I report it. This is why I
> prefer to come here first and be assured it is indeed a bug not just
> a clumsy mistake from my part.
You should probably still mention it here, but I wouldn't avoid opening
a JIRA (with all the necessary and useful information).
We can always close it if we decide it's not really a bug - no one is
going to object to a bug report with the quality of information in your
original email.
> Here you go: https://issues.apache.org/jira/browse/PROTON-1292�
Thanks.
Andrew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org
RE: [Qpid Proton 0.12.2] errno not thread-safe on Solaris
Posted by Adel Boutros <ad...@live.com>.
Hello Andrew,
I wanted to make sure it was a bug before I report it. This is why I prefer to come here first and be assured it is indeed a bug not just a clumsy mistake from my part.
Here you go: https://issues.apache.org/jira/browse/PROTON-1292
Regards,
Adel
> Subject: Re: [Qpid Proton 0.12.2] errno not thread-safe on Solaris
> From: astitcher@redhat.com
> To: users@qpid.apache.org
> Date: Mon, 29 Aug 2016 10:59:04 -0400
>
> Adel
>
> Raise an JIRA issue so this does not get overlooked or forgotten.
>
> [As a side point, this list is not the best way to report bugs, but
> entirely the best way to ask for advice and help!]
>
> Andrew
>
> On Mon, 2016-08-29 at 09:32 +0200, Adel Boutros wrote:
> > Hello,
> >
> > 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[1].
> >
> > The issue is that errno is not thread safe[2] 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[2].
> >
> > Do you think this flag could be set by default in the CMakeList of
> > proton to avoid others having the same issue?
> >
> > On Solaris:
> > /usr/include/errno.h
> >
> > #if defined(_REENTRANT) || defined(_TS_ERRNO) || _POSIX_C_SOURCE - 0
> > >= 199506L
> > extern int *___errno();
> > #define errno (*(___errno()))
> > #else
> > extern int errno;
> > /* ANSI C++ requires that errno be a macro */
> > #if __cplusplus >= 199711L
> > #define errno errno
> > #endif
> > #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.
> >
> > Regards,
> > Adel
> >
> > [1]: https://github.com/apache/qpid-proton/blob/0.12.2/proton-c/src/p
> > osix/io.c (line 187-188)
> > [2]: http://stackoverflow.com/questions/1694164/is-errno-thread-safe
> > [3]: http://stackoverflow.com/questions/875789/gcc-do-i-need-d-reentr
> > ant-with-pthreads
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
Re: [Qpid Proton 0.12.2] errno not thread-safe on Solaris
Posted by Andrew Stitcher <as...@redhat.com>.
Adel
Raise an JIRA issue so this does not get overlooked or forgotten.
[As a side point, this list is not the best way to report bugs, but
entirely the best way to ask for advice and help!]
Andrew
On Mon, 2016-08-29 at 09:32 +0200, Adel Boutros wrote:
> Hello,
>
> 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[1].
>
> The issue is that errno is not thread safe[2] 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[2].
>
> Do you think this flag could be set by default in the CMakeList of
> proton to avoid others having the same issue?
>
> On Solaris:
> /usr/include/errno.h
>
> #if defined(_REENTRANT) || defined(_TS_ERRNO) || _POSIX_C_SOURCE - 0
> >= 199506L
> extern int *___errno();
> #define errno (*(___errno()))
> #else
> extern int errno;
> /* ANSI C++ requires that errno be a macro */
> #if __cplusplus >= 199711L
> #define errno errno
> #endif
> #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.
>
> Regards,
> Adel
>
> [1]: https://github.com/apache/qpid-proton/blob/0.12.2/proton-c/src/p
> osix/io.c (line 187-188)
> [2]: http://stackoverflow.com/questions/1694164/is-errno-thread-safe�
> [3]: http://stackoverflow.com/questions/875789/gcc-do-i-need-d-reentr
> ant-with-pthreads�
> � � ��� ��
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org