Re: [Libevent-users] Process terminating with default action of signal 13 (SIGPIPE)
Hi! On Fri, Jun 26, 2009 at 03:01:19PM +0600, Rauan Maemirov wrote: >Hi, Clint. Thanks for the answer. But I was interested how can i solve >it in the scope of libevent. You can't. Handling signals is a global effect, so libraries shouldn't touch them implicitly, instead the main program should. It's the way it is with Unix/POSIX signals. SIGPIPE is just a very nasty case because of its default settings. >[...] Kind regards, Hannah. ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Process terminating with default action of signal 13 (SIGPIPE)
Hi! On Fri, Jun 26, 2009 at 04:37:53PM +0800, Clint Webb wrote: >[...] >2. You can check the status of the socket before you write to it. That's racey. >socklen_t err_len; >int error; >err_len = sizeof(error); >getsockopt(handle, SOL_SOCKET, SO_ERROR, &error, &err_len); >if (error != ESHUTDOWN) { > // actually, I cant remember what E code to check, > // ESHUTDOWN might not be it... you can look that up yourself. >} And then the remote side closes it, then you write and get SIGPIPE anyway. That's a classical race condition. >As an aside, most people dont get this error under 'normal' conditions >because as part of their process they tend to always do a read before >attempting a write. The same kind of race condition. It may occur much more seldom than when you write without reading (or checking SO_ERROR) before, but it *will* occur eventually. >[...] The only sane way is ignoring SIGPIPE. SIGPIPE is fine for Unix pipe filter programs. For network daemons SIGPIPE's only disposition is to be ignored (and to handle EPIPE instead). Kind regards, Hannah. ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Process terminating with default action of signal 13 (SIGPIPE)
Oops. Thank you, Clint. First variant is exactly what i need. Don't mention my previous email. :) 2009/6/26 Clint Webb : > SIGPIPE happens normally because you attempt to write to a socket that has > closed. > > There are a couple of things you can do... > > 1. You can disable SIGPIPE notification. Something like: > > struct sigaction sa; > sa.sa_handler = SIG_IGN; > sa.sa_flags = 0; > if (sigemptyset(&sa.sa_mask) == -1 || sigaction(SIGPIPE, &sa, 0) == -1) { > perror("failed to ignore SIGPIPE; sigaction"); > exit(EXIT_FAILURE); > > > > } > > 2. You can check the status of the socket before you write to it. > > socklen_t err_len; > int error; > err_len = sizeof(error); > getsockopt(handle, SOL_SOCKET, SO_ERROR, &error, &err_len); > if (error != ESHUTDOWN) { > // actually, I cant remember what E code to check, > // ESHUTDOWN might not be it... you can look that up yourself. > } > > > As an aside, most people dont get this error under 'normal' conditions > because as part of their process they tend to always do a read before > attempting a write. A read would detect the closed socket, and you > wouldn't bother doing the write. You are probably doing something like > that, but when doing it rapidly, connection is closing in-between the read > and write hence getting the sigpipe. > > > > On Fri, Jun 26, 2009 at 3:01 PM, Rauan Maemirov wrote: >> >> Hi, all. >> I'm having issues with libevent. >> >> When I use siege or something like that, everything's ok. But when I >> open link in browser, and start to push F5 like a crazy, daemon exits. >> Valgrind shows: >> >> ... >> Process terminating with default action of signal 13 (SIGPIPE) >> ==5635== at 0x5B2BF90: write (in /lib/libc-2.9.so) >> ==5635== by 0x4E335BF: evbuffer_write (buffer.c:414) >> ==5635== by 0x4E38819: evhttp_write (http.c:685) >> ==5635== by 0x4E33297: event_base_loop (event.c:392) >> ==5635== by 0x402E5F: main (myapp.c:283) // here goes event_dispatch() >> --5879-- Discarding syms at 0x91db2e0-0x91e0498 in >> /lib/libnss_compat-2.9.so due to munmap() >> --5879-- Discarding syms at 0x93e5040-0x93eb408 in >> /lib/libnss_nis-2.9.so due to munmap() >> --5879-- Discarding syms at 0x95f0020-0x95f7c48 in >> /lib/libnss_files-2.9.so due to munmap() >> ... >> >> I deem, it's because of interrupted connections. How should I handle it? >> ___ >> Libevent-users mailing list >> Libevent-users@monkey.org >> http://monkeymail.org/mailman/listinfo/libevent-users > > > > -- > "Be excellent to each other" > ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Process terminating with default action of signal 13 (SIGPIPE)
Hi, Clint. Thanks for the answer. But I was interested how can i solve it in the scope of libevent. As u see, it's a pipe from libevent, so I thought, that I should check it by libevent's tools or kind of... should I use your suggestions anyway? 2009/6/26 Clint Webb : > SIGPIPE happens normally because you attempt to write to a socket that has > closed. > > There are a couple of things you can do... > > 1. You can disable SIGPIPE notification. Something like: > > struct sigaction sa; > sa.sa_handler = SIG_IGN; > sa.sa_flags = 0; > if (sigemptyset(&sa.sa_mask) == -1 || sigaction(SIGPIPE, &sa, 0) == -1) { > perror("failed to ignore SIGPIPE; sigaction"); > exit(EXIT_FAILURE); > > > > } > > 2. You can check the status of the socket before you write to it. > > socklen_t err_len; > int error; > err_len = sizeof(error); > getsockopt(handle, SOL_SOCKET, SO_ERROR, &error, &err_len); > if (error != ESHUTDOWN) { > // actually, I cant remember what E code to check, > // ESHUTDOWN might not be it... you can look that up yourself. > } > > > As an aside, most people dont get this error under 'normal' conditions > because as part of their process they tend to always do a read before > attempting a write. A read would detect the closed socket, and you > wouldn't bother doing the write. You are probably doing something like > that, but when doing it rapidly, connection is closing in-between the read > and write hence getting the sigpipe. > > > > On Fri, Jun 26, 2009 at 3:01 PM, Rauan Maemirov wrote: >> >> Hi, all. >> I'm having issues with libevent. >> >> When I use siege or something like that, everything's ok. But when I >> open link in browser, and start to push F5 like a crazy, daemon exits. >> Valgrind shows: >> >> ... >> Process terminating with default action of signal 13 (SIGPIPE) >> ==5635== at 0x5B2BF90: write (in /lib/libc-2.9.so) >> ==5635== by 0x4E335BF: evbuffer_write (buffer.c:414) >> ==5635== by 0x4E38819: evhttp_write (http.c:685) >> ==5635== by 0x4E33297: event_base_loop (event.c:392) >> ==5635== by 0x402E5F: main (myapp.c:283) // here goes event_dispatch() >> --5879-- Discarding syms at 0x91db2e0-0x91e0498 in >> /lib/libnss_compat-2.9.so due to munmap() >> --5879-- Discarding syms at 0x93e5040-0x93eb408 in >> /lib/libnss_nis-2.9.so due to munmap() >> --5879-- Discarding syms at 0x95f0020-0x95f7c48 in >> /lib/libnss_files-2.9.so due to munmap() >> ... >> >> I deem, it's because of interrupted connections. How should I handle it? >> ___ >> Libevent-users mailing list >> Libevent-users@monkey.org >> http://monkeymail.org/mailman/listinfo/libevent-users > > > > -- > "Be excellent to each other" > ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Process terminating with default action of signal 13 (SIGPIPE)
SIGPIPE happens normally because you attempt to write to a socket that has closed. There are a couple of things you can do... 1. You can disable SIGPIPE notification. Something like: struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = 0; if (sigemptyset(&sa.sa_mask) == -1 || sigaction(SIGPIPE, &sa, 0) == -1) { perror("failed to ignore SIGPIPE; sigaction"); exit(EXIT_FAILURE); } 2. You can check the status of the socket before you write to it. socklen_t err_len; int error; err_len = sizeof(error); getsockopt(handle, SOL_SOCKET, SO_ERROR, &error, &err_len); if (error != ESHUTDOWN) { // actually, I cant remember what E code to check, // ESHUTDOWN might not be it... you can look that up yourself. } As an aside, most people dont get this error under 'normal' conditions because as part of their process they tend to always do a read before attempting a write. A read would detect the closed socket, and you wouldn't bother doing the write. You are probably doing something like that, but when doing it rapidly, connection is closing in-between the read and write hence getting the sigpipe. On Fri, Jun 26, 2009 at 3:01 PM, Rauan Maemirov wrote: > Hi, all. > I'm having issues with libevent. > > When I use siege or something like that, everything's ok. But when I > open link in browser, and start to push F5 like a crazy, daemon exits. > Valgrind shows: > > ... > Process terminating with default action of signal 13 (SIGPIPE) > ==5635==at 0x5B2BF90: write (in /lib/libc-2.9.so) > ==5635==by 0x4E335BF: evbuffer_write (buffer.c:414) > ==5635==by 0x4E38819: evhttp_write (http.c:685) > ==5635==by 0x4E33297: event_base_loop (event.c:392) > ==5635==by 0x402E5F: main (myapp.c:283) // here goes event_dispatch() > --5879-- Discarding syms at 0x91db2e0-0x91e0498 in > /lib/libnss_compat-2.9.so due to munmap() > --5879-- Discarding syms at 0x93e5040-0x93eb408 in > /lib/libnss_nis-2.9.so due to munmap() > --5879-- Discarding syms at 0x95f0020-0x95f7c48 in > /lib/libnss_files-2.9.so due to munmap() > ... > > I deem, it's because of interrupted connections. How should I handle it? > ___ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkeymail.org/mailman/listinfo/libevent-users > -- "Be excellent to each other" ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Process terminating with default action of signal 13 (SIGPIPE)
Hi Rauan, Set your daemon to ignore SIGPIPE. Or register an empty signal handler for SIGPIPE. Code from my own daemon that had this too: if(signal(SIGPIPE, SIG_IGN) == SIG_ERR) ... print errno Best regards, Wouter On 06/26/2009 09:01 AM, Rauan Maemirov wrote: > Hi, all. > I'm having issues with libevent. > > When I use siege or something like that, everything's ok. But when I > open link in browser, and start to push F5 like a crazy, daemon exits. > Valgrind shows: > > ... > Process terminating with default action of signal 13 (SIGPIPE) > ==5635==at 0x5B2BF90: write (in /lib/libc-2.9.so) > ==5635==by 0x4E335BF: evbuffer_write (buffer.c:414) > ==5635==by 0x4E38819: evhttp_write (http.c:685) > ==5635==by 0x4E33297: event_base_loop (event.c:392) > ==5635==by 0x402E5F: main (myapp.c:283) // here goes event_dispatch() > --5879-- Discarding syms at 0x91db2e0-0x91e0498 in > /lib/libnss_compat-2.9.so due to munmap() > --5879-- Discarding syms at 0x93e5040-0x93eb408 in > /lib/libnss_nis-2.9.so due to munmap() > --5879-- Discarding syms at 0x95f0020-0x95f7c48 in > /lib/libnss_files-2.9.so due to munmap() > ... > > I deem, it's because of interrupted connections. How should I handle it? > ___ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkeymail.org/mailman/listinfo/libevent-users ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users