unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Thread + Socket + Pipes Bug?
@ 2003-08-07  7:58 Robert Marlow
       [not found] ` <m3adalb1ni.fsf@laruns.ossau.uklinux.net>
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Marlow @ 2003-08-07  7:58 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Hi

I've been spending ages on this bug and can't figure it out. I'm pretty
sure it's not a bug in something I've done so I'm submitting it here as
a possible guile bug. If it's not a bug in guile, many apologies but
please let me know what's gone wrong. 

I've attached two trimmed-down scripts which reproduce the bug. If you
place them in the same directory and run buggy.scm then you should be
able to connect to tcp port 6008 and start dumping data. The bug occurs
when you do this, crashing with an error as follows:

ERROR: In procedure select:
ERROR: Bad file descriptor

In my playing around I seem to have narrowed it down to being caused by
select working on one thread and a pipe being written to on another
thread. I couldn't determine much more than that. I do know the bug
occurs on both Solaris and GNU/Linux.

I hate to be whiney but my progress here at work is pretty well at a
standstill until either this bug is resolved or I dump guile and settle
for something like perl (which I really, really don't want to do). So
please help.


-- 
Regards,

Robert Marlow




[-- Attachment #2: buggy.scm --]
[-- Type: text/x-scheme, Size: 1811 bytes --]

#!/usr/bin/guile \
-e main -s
!#

(use-modules (ice-9 threads)
             (ice-9 popen))

(define mutex (make-mutex))
(define message-ready (make-condition-variable))

(define message "")

(define (main args)
  (begin-thread (thread))
  (begin-thread (thread))
  (begin-thread (thread))
  (begin-thread (thread))
  (begin-thread (thread))
  (let ((sock #f)
        (fileno #f))
    (lock-mutex mutex)
    (set! sock (socket AF_INET SOCK_STREAM 0))
    (unlock-mutex mutex)
    (bind sock AF_INET INADDR_ANY 6008)
    (listen sock 5)
    (while
     #t
     (let* ((client-connection (accept/no-block sock))
            (client-details (cdr client-connection))
            (client (car client-connection)))
       (lock-mutex mutex)
       (do ((line (read-line client) (read-line client)))
           ((eof-object? line)
            (shutdown client 2))
         (set! message (string-append message line "\n")))
       (signal-condition-variable message-ready)
       (unlock-mutex mutex)))))


(define (thread)
  (while
   #t
   
   (lock-mutex mutex)
   (if (not (> (string-length message) 0))
       (wait-condition-variable message-ready mutex)
       (let ((outgoing message))
         (set! message "")
         (unlock-mutex mutex)
         (piper outgoing)))
   (unlock-mutex mutex)))


(define (piper message)
  (lock-mutex mutex)
  (let ((pipe (open-output-pipe "./buggy-companion.scm")))
    (display message pipe)
    (close-port pipe))
  (unlock-mutex mutex))
    



(define (accept/no-block s)
  (if (null? (car (select (vector s) '() '()))) ; This select complains
      (accept/no-block s)
      (let ((client #f))
        (lock-mutex mutex)
        (set! client (accept s))
        (unlock-mutex mutex)
        client)))

[-- Attachment #3: buggy-companion.scm --]
[-- Type: text/x-scheme, Size: 242 bytes --]

#!/usr/bin/guile \
-e main -s
!#

(define (main args)
  (let ((str ""))
    (do ((line (read-line) (read-line)))
	((eof-object? line))
      (set! str (string-append str line "\n")))
     (sleep 10)
     (display str)))
	    
    

[-- Attachment #4: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
       [not found] ` <m3adalb1ni.fsf@laruns.ossau.uklinux.net>
@ 2003-08-08  1:09   ` Robert Marlow
  2003-08-10 21:19     ` Neil Jerram
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Marlow @ 2003-08-08  1:09 UTC (permalink / raw)
  Cc: bug-guile

Hi Neil

Sorry, I think I neglected to mention. I'm using Guile 1.6.4 on Solaris
and GNU/Linux.

Thanks heaps for checking it out.


On Fri, 2003-08-08 at 05:25, Neil Jerram wrote:
> Robert,
> 
> You probably said in your earlier reports, but ... which version(s) of
> Guile do you see this bug with?
> 
> (I'll try to make time over the weekend to investigate ...)
> 
> Thanks,
>         Neil
-- 
Regards,

Robert Marlow







_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
  2003-08-08  1:09   ` Robert Marlow
@ 2003-08-10 21:19     ` Neil Jerram
  2003-08-11 10:02       ` bobstopper
  0 siblings, 1 reply; 8+ messages in thread
From: Neil Jerram @ 2003-08-10 21:19 UTC (permalink / raw)
  Cc: bug-guile

Robert,

I'm having trouble reproducing the problem, and I also have some
questions about the code.

1. Repro

Can you be precise about "dumping data" to port 6008.  I've tried
running with just ./buggy.scm in one window, and the following in
another window...

[neil@laruns ~]$ telnet localhost 6008
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
bye
bye again
^]
telnet> close
Connection closed.
[neil@laruns ~]$ telnet localhost 6008
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
hello again
hello 3
hello 4
^]
telnet> close
Connection closed.

...but I don't see any error (or any other output/result) anywhere.

2. Code

Why do you need to lock and unlock the mutex so much on the main
thread?  It looks to me as though the data protected by the mutex is
just `message' - is that correct?

Regards,
        Neil


>>>>> "Robert" == Robert Marlow <bobstopper@australispro.com.au> writes:

    Robert> Hi Neil
    Robert> Sorry, I think I neglected to mention. I'm using Guile 1.6.4 on Solaris
    Robert> and GNU/Linux.

    Robert> Thanks heaps for checking it out.


    Robert> On Fri, 2003-08-08 at 05:25, Neil Jerram wrote:
    >> Robert,
    >> 
    >> You probably said in your earlier reports, but ... which version(s) of
    >> Guile do you see this bug with?
    >> 
    >> (I'll try to make time over the weekend to investigate ...)
    >> 
    >> Thanks,
    >> Neil
    Robert> -- 
    Robert> Regards,

    Robert> Robert Marlow









_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
  2003-08-10 21:19     ` Neil Jerram
@ 2003-08-11 10:02       ` bobstopper
  2003-08-12 23:06         ` Neil Jerram
  0 siblings, 1 reply; 8+ messages in thread
From: bobstopper @ 2003-08-11 10:02 UTC (permalink / raw)


Hi Neil

Thanks for your response. My responses are below


On Sun, Aug 10, 2003 at 10:19:52PM +0100, Neil Jerram wrote:
> Robert,
> 
> I'm having trouble reproducing the problem, and I also have some
> questions about the code.
> 
> 1. Repro
> 
> Can you be precise about "dumping data" to port 6008.  I've tried
> running with just ./buggy.scm in one window, and the following in
> another window...
> 
> [neil@laruns ~]$ telnet localhost 6008
> Trying ::1...
> telnet: connect to address ::1: Connection refused
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> bye
> bye again
> ^]
> telnet> close
> Connection closed.
> [neil@laruns ~]$ telnet localhost 6008
> Trying ::1...
> telnet: connect to address ::1: Connection refused
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> hello
> hello again
> hello 3
> hello 4
> ^]
> telnet> close
> Connection closed.
> 
> ...but I don't see any error (or any other output/result) anywhere.

Ok, well that's pretty annoying. That's certainly what I do to get it
complaining. Sometimes it takes a few attempts at dumping output there
before it complains but generally speaking it will crash in the first
attempt. I've had it doing it on 3 different computers. Do you have
anything related installed which might be working around the problem?

By the way, the output drawn from the port 6008 connection should
appear on the server terminal after about 10 seconds under normal
operation. That's also where any errors will appear.


> 2. Code
> 
> Why do you need to lock and unlock the mutex so much on the main
> thread?  It looks to me as though the data protected by the mutex is
> just `message' - is that correct?

Yeah, I started out just protecting that but because I was getting
file descriptor errors everywhere and because they always seemed
related to the threading, I started locking whenever I performed
operations on file descriptors. That did seem to work for most of the
errors. However nothing I lock seems to help this particular problem
with select without reverting the whole program to a thread blocking
accept.

Am I correct that simple file descriptor operations should not need
mutex locks? If so, that's probably a related bug which you could reveal
simply by removing unnecessary mutex locks around port/pipe
operations. Upon doing that the errors should include more "bad file
descriptor" errors and eventually broken pipes.


-- 
Regards,

Robert Marlow


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
  2003-08-11 10:02       ` bobstopper
@ 2003-08-12 23:06         ` Neil Jerram
  2003-08-14 10:43           ` Robert Marlow
  2003-08-14 14:08           ` Robert Marlow
  0 siblings, 2 replies; 8+ messages in thread
From: Neil Jerram @ 2003-08-12 23:06 UTC (permalink / raw)
  Cc: bug-guile

>>>>> "bobstopper" == bobstopper  <bobstopper@australispro.com.au> writes:

    bobstopper> Ok, well that's pretty annoying. That's certainly what
    bobstopper> I do to get it complaining. [...] Do you have anything
    bobstopper> related installed which might be working around the
    bobstopper> problem?

Well I'm actually using the 1.6.x CVS branch as it was shortly before
the 1.6.4 release.  (It seems impossible right now to get a 1.6.4
release - according to GNU and mirror sites it is being checked for
authenticity...?)  Other than that my box is a standard GNU/Linux.

Do you happen to know whether the problem repros on any other Guile
releases, or on the 1.7.x CVS branch?

        Neil



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
  2003-08-12 23:06         ` Neil Jerram
@ 2003-08-14 10:43           ` Robert Marlow
  2003-08-15 22:35             ` Neil Jerram
  2003-08-14 14:08           ` Robert Marlow
  1 sibling, 1 reply; 8+ messages in thread
From: Robert Marlow @ 2003-08-14 10:43 UTC (permalink / raw)
  Cc: bug-guile

I'm having a bit of trouble with libtool trying to get 1.7 installed
from CVS.

I've still got the guile-1.6.4 version I have installed available
though. I've put it in webspace at:
http://system.piscescom.com/~rmarlow/guile-1.6.4.tar.bz2
If you want to try that. I'll continue to see if I can get 1.7
installed. It'd be handy to have more version variance for my own
testing anyway.


On Wed, 2003-08-13 at 07:06, Neil Jerram wrote:
> >>>>> "bobstopper" == bobstopper  <bobstopper@australispro.com.au> writes:
> 
>     bobstopper> Ok, well that's pretty annoying. That's certainly what
>     bobstopper> I do to get it complaining. [...] Do you have anything
>     bobstopper> related installed which might be working around the
>     bobstopper> problem?
> 
> Well I'm actually using the 1.6.x CVS branch as it was shortly before
> the 1.6.4 release.  (It seems impossible right now to get a 1.6.4
> release - according to GNU and mirror sites it is being checked for
> authenticity...?)  Other than that my box is a standard GNU/Linux.
> 
> Do you happen to know whether the problem repros on any other Guile
> releases, or on the 1.7.x CVS branch?
> 
>         Neil
-- 
Regards,

Robert Marlow



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
  2003-08-12 23:06         ` Neil Jerram
  2003-08-14 10:43           ` Robert Marlow
@ 2003-08-14 14:08           ` Robert Marlow
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Marlow @ 2003-08-14 14:08 UTC (permalink / raw)
  Cc: bug-guile

Ok, got 1.7 installed. No go though - for me it just segfaults as soon
as the client closes the TCP port. strace gives me this at the end:
read(6, "", 1)                          = 0
shutdown(6, 2 /* send and receive */)   = 0
kill(23511, SIGRTMIN)                   = 0
kill(23511, SIGRTMIN)                   = 0
select(6, [5], [], [], NULL)            = ? ERESTARTNOHAND (To be
restarted)
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

--debug for guile gives me nada. 

I'm thinking I'll leave that one alone for now and figure out what's
going on with 1.6.3/4. Since I'm using 1.6.3 and 1.6.4 it's strange that
your pre-1.6.4 release version right between the two releases I'm using
isn't displaying the same bug. It's gotta be something else you've got
that I don't...


On Wed, 2003-08-13 at 07:06, Neil Jerram wrote:
> >>>>> "bobstopper" == bobstopper  <bobstopper@australispro.com.au> writes:
> 
>     bobstopper> Ok, well that's pretty annoying. That's certainly what
>     bobstopper> I do to get it complaining. [...] Do you have anything
>     bobstopper> related installed which might be working around the
>     bobstopper> problem?
> 
> Well I'm actually using the 1.6.x CVS branch as it was shortly before
> the 1.6.4 release.  (It seems impossible right now to get a 1.6.4
> release - according to GNU and mirror sites it is being checked for
> authenticity...?)  Other than that my box is a standard GNU/Linux.
> 
> Do you happen to know whether the problem repros on any other Guile
> releases, or on the 1.7.x CVS branch?
> 
>         Neil
-- 
Regards,

Robert Marlow



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Thread + Socket + Pipes Bug?
  2003-08-14 10:43           ` Robert Marlow
@ 2003-08-15 22:35             ` Neil Jerram
  0 siblings, 0 replies; 8+ messages in thread
From: Neil Jerram @ 2003-08-15 22:35 UTC (permalink / raw)
  Cc: bug-guile

>>>>> "Robert" == Robert Marlow <bobstopper@australispro.com.au> writes:

    Robert> I've still got the guile-1.6.4 version I have installed available
    Robert> though. I've put it in webspace at:
    Robert> http://system.piscescom.com/~rmarlow/guile-1.6.4.tar.bz2
    Robert> If you want to try that. I'll continue to see if I can get 1.7
    Robert> installed. It'd be handy to have more version variance for my own
    Robert> testing anyway.

Thanks, I've built and installed this now.  I configured with
"./configure --with-threads" - does that match what you did?

Anyway, still no luck.  I've added (format) statements all over so I
can see what's happening, and right now it seems that
./buggy-companion.scm isn't even starting up when invoked from the
worker threads of ./buggy.scm.

If, however, I just fire up Guile and do
guile> (use-modules (ice-9 popen))
guile> (use-modules (ice-9 threads))
guile> (define p (open-output-pipe "./buggy-companion.scm"))
guile> (display "hello there\n" p)
guile> (close-port p)
I see output indicating that ./buggy-companion.scm is running
correctly.

Any thoughts?

        Neil



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-08-15 22:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-07  7:58 Thread + Socket + Pipes Bug? Robert Marlow
     [not found] ` <m3adalb1ni.fsf@laruns.ossau.uklinux.net>
2003-08-08  1:09   ` Robert Marlow
2003-08-10 21:19     ` Neil Jerram
2003-08-11 10:02       ` bobstopper
2003-08-12 23:06         ` Neil Jerram
2003-08-14 10:43           ` Robert Marlow
2003-08-15 22:35             ` Neil Jerram
2003-08-14 14:08           ` Robert Marlow

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).