* Writing to socket after shutdown
@ 2010-08-03 2:03 Jon Herron
2010-08-26 20:24 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Jon Herron @ 2010-08-03 2:03 UTC (permalink / raw)
To: Guile Devel
Hello all,
I had an issue with a program recently where I tried to write to a socket that
had been shutdown for transmission. This ends up causing guile to halt without
any warning - no exceptions or backtrace available that I can see. I am using
guile compiled from master, but get the same results with 1.8.7. Is it correct
to assume that I should be able to catch an exception under this circumstance?
Hope a boiled down example inline is ok:
;;;;;;;;;;;;;;;;;;;;
(define (get-addr hostname)
(let ((host (gethostbyname hostname)))
(car (hostent:addr-list host))))
(catch #t
(lambda ()
(let ((remote (socket PF_INET SOCK_STREAM 0)) (hostname "www.gnu.org"))
(connect remote AF_INET (get-addr hostname) 80)
(display (string-append "GET / HTTP/1.0\r\nHost: " hostname "\r\n\r\n")
remote)
(display "Sent request...\n")
(shutdown remote 1)
(display "Shutdown socket for sending...\n")
(display "oops, socket is shutdown for sending...\n" remote)
(shutdown remote 0)
(display "Shutdown socket for receiving...\n")
(close remote)))
(lambda (key . args)
(display "Caught exception...\n")
(display key)(newline)
(display args)(newline)))
(display "Done.\n")
;;;;;;;;;;;;;;;;;;;;
Thanks,
Jon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Writing to socket after shutdown
2010-08-03 2:03 Writing to socket after shutdown Jon Herron
@ 2010-08-26 20:24 ` Andy Wingo
2010-08-27 14:01 ` Jon Herron
0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2010-08-26 20:24 UTC (permalink / raw)
To: Jon Herron; +Cc: Guile Devel
Hi Jon,
On Mon 02 Aug 2010 22:03, Jon Herron <jon.herron@yahoo.com> writes:
> I had an issue with a program recently where I tried to write to a socket that
> had been shutdown for transmission. This ends up causing guile to halt without
> any warning - no exceptions or backtrace available that I can see. I am using
> guile compiled from master, but get the same results with 1.8.7. Is it correct
> to assume that I should be able to catch an exception under this circumstance?
I pasted your example at the REPL run via meta/gdb-uninstalled-guile and
got a SIGPIPE:
Sent request...
Shutdown socket for sending...
Program received signal SIGPIPE, Broken pipe.
0x000000324e40e42d in write () from /lib64/libpthread.so.0
(gdb) c
Continuing.
Caught exception...
system-error
(fport_write ~A (Broken pipe) (32))
scheme@(guile-user)>
But the same thing does not work when run at a normal (not in GDB)
REPL. Hmm.
I think SIGPIPE is the right thing to do here; the problem is that Guile
does not appear to catch it by default. I'm not sure why the with-gdb
case is different from the normal case. Indeed adding the following line
does make it work:
(sigaction SIGPIPE (lambda args (error "got a sigpipe, yo")))
Now, I guess the question is, what should happen when Guile gets a
signal? Should Guile install a signal handler by default? The current
situation is not particularly intuitive.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Writing to socket after shutdown
2010-08-26 20:24 ` Andy Wingo
@ 2010-08-27 14:01 ` Jon Herron
2010-08-27 15:22 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Jon Herron @ 2010-08-27 14:01 UTC (permalink / raw)
To: Andy Wingo; +Cc: Guile Devel
Hi Andy -
Thanks for the reply. I think SIGPIPE is indeed the right thing to do. I ended
up adding a sighandler to my application and it solved the problem. I suppose it
would be nice for Guile to at least display the error on exit - as in the gdb
REPL example of yours, if not throw an exception so the user's application can
catch. It seems to me the sighandler is more of the C way, where catch/throw is
closer to the Scheme way - not sure if that is general consensus or not.
Thanks again for looking at the issue,
Jon
----- Original Message ----
From: Andy Wingo <wingo@pobox.com>
To: Jon Herron <jon.herron@yahoo.com>
Cc: Guile Devel <guile-devel@gnu.org>
Sent: Thu, August 26, 2010 4:24:37 PM
Subject: Re: Writing to socket after shutdown
Hi Jon,
On Mon 02 Aug 2010 22:03, Jon Herron <jon.herron@yahoo.com> writes:
> I had an issue with a program recently where I tried to write to a socket
>that
>
> had been shutdown for transmission. This ends up causing guile to halt without
> any warning - no exceptions or backtrace available that I can see. I am using
> guile compiled from master, but get the same results with 1.8.7. Is it correct
> to assume that I should be able to catch an exception under this circumstance?
I pasted your example at the REPL run via meta/gdb-uninstalled-guile and
got a SIGPIPE:
Sent request...
Shutdown socket for sending...
Program received signal SIGPIPE, Broken pipe.
0x000000324e40e42d in write () from /lib64/libpthread.so.0
(gdb) c
Continuing.
Caught exception...
system-error
(fport_write ~A (Broken pipe) (32))
scheme@(guile-user)>
But the same thing does not work when run at a normal (not in GDB)
REPL. Hmm.
I think SIGPIPE is the right thing to do here; the problem is that Guile
does not appear to catch it by default. I'm not sure why the with-gdb
case is different from the normal case. Indeed adding the following line
does make it work:
(sigaction SIGPIPE (lambda args (error "got a sigpipe, yo")))
Now, I guess the question is, what should happen when Guile gets a
signal? Should Guile install a signal handler by default? The current
situation is not particularly intuitive.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Writing to socket after shutdown
2010-08-27 14:01 ` Jon Herron
@ 2010-08-27 15:22 ` Andy Wingo
0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2010-08-27 15:22 UTC (permalink / raw)
To: Jon Herron; +Cc: Guile Devel
On Fri 27 Aug 2010 07:01, Jon Herron <jon.herron@yahoo.com> writes:
> Hi Andy -
>
> Thanks for the reply. I think SIGPIPE is indeed the right thing to do. I ended
> up adding a sighandler to my application and it solved the problem. I suppose it
> would be nice for Guile to at least display the error on exit - as in the gdb
> REPL example of yours, if not throw an exception so the user's application can
> catch. It seems to me the sighandler is more of the C way, where catch/throw is
> closer to the Scheme way - not sure if that is general consensus or not.
I filed this bug.
https://savannah.gnu.org/bugs/index.php?30890
I think you're right that we should handle signals, but we need to do so
in a way that is not going to interfere adversely with embedded uses of
Guile. And then there are threads. Bleagh ;)
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-27 15:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-03 2:03 Writing to socket after shutdown Jon Herron
2010-08-26 20:24 ` Andy Wingo
2010-08-27 14:01 ` Jon Herron
2010-08-27 15:22 ` Andy Wingo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).