You need to put signal handling in your programs.  a SIGPIPE is generated
when you attempt to write data to a socket that has closed.

If you look in the memcached (the server not the library) source, you would
see something that looked like:

        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);
        }

You would need something similar in your own code.   Most programmers dont
do this, and get away with it because they happen to always do a read first,
and detect the closed socket at that point.

As to why you are getting a sigpipe, maybe the library could do better
checking before attempting to send, but I doubt it would be as efficient as
you adding a sigpipe signal handler.


On Wed, Nov 26, 2008 at 10:32 PM, Bill Moseley <[EMAIL PROTECTED]> wrote:

>
> I'm getting a SIGPIPE when trying to read the cache after I kill a
> memcached server.
>
> I'm using the Perl module Memcached::libmemcached Version 0.2101 (with
> libmemcached-0.21 embedded).  I also installed libmemcached-0.23
> before installing the Perl module, but the module is reporting it's
> using libmemcached 0.21.
>
>
> I have a simple script that starts six memcached servers, sets some
> items into the cache, then fetches them back.
>
> It then kills one of the servers and attempts to read all the keys
> again.  At this point I get a SIGPIPE (according to just a simple
> strace) and the script dies.
>
> write(3, "get a604c5769da20dea8cf84c51abd3"..., 39) = 39
> read(3, "", 8196)                       = 0
> write(3, "get 79ee55b4f57b673b01d2e173cf3a"..., 39) = -1 EPIPE (Broken
> pipe)
> --- SIGPIPE (Broken pipe) @ 0 (0) ---
> +++ killed by SIGPIPE +++
> Process 7122 detached
>
> If I write a similar script using Cache::Memcached I don't see this
> behavior.  (Cache::Memcached doesn't use libmemcached.)
>
> I'm a bit new to libmemcached, so before I start digging in is this
> something anyone else has seen?  Or for that matter, can replicate?
>
> I'll try and write a C program that tries this on libmemcaced but I
> can't write C as fast as I used to.
>
> Thanks,
>
>
> BTW -- If curious, here's the two scripts I'm using:
>
> http://hank.org/libmemd.pl  (using  Memcached::libmemcached )
> http://hank.org/memd.pl     (using  Cache::Memcached )
>
> Output from first is:
>
>    starting 6 servers
>
>    ----------- Items in servers ---------
>    pid:8127 - localhost:12001 = 0
>    pid:8128 - localhost:12002 = 0
>    pid:8129 - localhost:12003 = 0
>    pid:8130 - localhost:12004 = 0
>    pid:8132 - localhost:12005 = 0
>    pid:8133 - localhost:12006 = 0
>    Total: 0
>
>    populating 2000 items
>
>    ----------- Items in servers ---------
>    pid:8127 - localhost:12001 = 318
>    pid:8128 - localhost:12002 = 346
>    pid:8129 - localhost:12003 = 338
>    pid:8130 - localhost:12004 = 340
>    pid:8132 - localhost:12005 = 339
>    pid:8133 - localhost:12006 = 319
>    Total: 2000
>
>    Hit: 2000.  Miss: 0.  Total: 2000
>    kill one server
>
>    ----------- Items in servers ---------
>    pid:8127 - localhost:12001 = 318
>    pid:8128 - localhost:12002 = 346
>    pid:8129 - localhost:12003 = 338
>    Port 12004 is removed
>    pid:8132 - localhost:12005 = 339
>    pid:8133 - localhost:12006 = 319
>    Total: 1660
>
>
>    Command terminated
>
>
> With the other script It will show something like:
>
>    Hit: 1660.  Miss: 340.  Total: 2000
>
>
>
>
>
> --
> Bill Moseley
> [EMAIL PROTECTED]
> Sent from my iMutt
>
>


-- 
"Be excellent to each other"

Reply via email to