> Is there anything one can do to test that an io.Writer is good before
> calling Write? That would detract from the elegance of using the
> interface but would at least be able to handle the error gracefully.
I don't see how this is possible. The connection could fail between the
test and the call to Write.
> Perhaps the best solution is to have the application add a sigpipe
> handler and perform a graceful response. Does anyone have any tricks?
On tip a Go program will install a SIGPIPE handler which ignores the
signal. That will cause a write to a failed socket connection or pipe
to fail with EPIPE. If an os.File gets more than 10 EPIPE errors, it
will flip the SIGPIPE handler back to the default, and raise a SIGPIPE
signal, causing the program to fail.
As far as I know a write to a network socket will simply return an EPIPE
error.
Are you sure you are getting a SIGPIPE signal? What OS? Are you on
weekly or r60?
Ian
> I was able to determine it was a sigpipe from running the test in gdb.
>
> .........
> Reading symbols from /home/paul/src/go-dbus/6.out...done.
> (gdb) run
> Starting program: /home/paul/src/go-dbus/6.out
> [Thread debugging using libthread_db enabled]
> [New Thread 0x7ffff781b700 (LWP 16921)]
> [New Thread 0x7ffff701a700 (LWP 16922)]
>
> Program received signal SIGPIPE, Broken pipe.
Ah, but this by itself doesn't prove anything. gdb stops when the
program receives any signal, in order to let you debug. The question is
what happens when you continue. If all is working well, the program
should simply catch and ignore the signal, which should in turn cause
the system call to return with an EPIPE error.
Ian
> I'm seeing the same behavior on tip
>
> version: weekly.2012-01-15 11354+
>
> .....
>
> Reading symbols from /home/paul/src/go-dbus/6.out...done.
> (gdb) run
> Starting program: /home/paul/src/go-dbus/6.out
> [Thread debugging using libthread_db enabled]
> [New Thread 0x7ffff781b700 (LWP 23944)]
> [New Thread 0x7ffff701a700 (LWP 23945)]
>
> Program received signal SIGPIPE, Broken pipe.
Again, this is expected behaviour when using gdb. It doesn't tell us
anything about how the program behaves when not using gdb.
Ian