[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help: Looking at the Sun makes you blind...



I don't know what causes the following problem, but it's worth a try
here.  It's probably too technical so feel free to ignore me...

So, I have that cute program that takes any simple I/O thing and turns
it into a server.  It worked perfectly well, until I moved from a
"SunOS 5.8" to a "SunOS 5.7" (Maybe they are Solaris 2.x?).  Anyway,
the perfect cute program soon turned into a monster...  It started to
mysteriously drop characters at weird places, and after a while it
would just stop responding.  After lots of attempts, to localize the
problem, I minimized it to starting the program:

  (define-values
    (server-output server-input server-pid server-error server-control)
    (apply values (process*/ports #f #f #f "./mxpost" "tagger.project")))

start two threads to handle output:

  (define (get-output outp name)
    (thread (lambda ()
              (let loop ()
                (let ((l (read-line outp 'any)))
                  (printf "~a: ~s~%" name l) (loop))))))
  (get-output server-error "ERR")
  (get-output server-output "OUT")

and throw some input in:

  (define (inp x)
    (fprintf server-input "~a~%" x) (flush-output server-input))
  (inp "...")

This works fine on 5.8, but on 5.7 when the subprocess is "big", it
will hang after a while -- scheme refusing to even get even any normal
input, making `kill' the only way out.  I said "big" because according
to my experiments, it seems that this is somehow related to timing --
"cat" works fine, a small script that echos input to both stdout and
stderr drops characters and the big program above drops characters
next to spaces (it's an NLP program so I guess there is some quick
pause between words) and hangs.

I thought that using `read-string-avail!' would make it better so I
tried replacing the ports before the above threads:

  (define (cat in out)
    (let* ((bufsize 4096) (buffer (make-string bufsize)))
      (let loop ()
        (let ((l (read-string-avail! buffer in)))
          (unless (eof-object? l)
            (display (if (< l bufsize) (substring buffer 0 l) buffer) out)
            (flush-output out)
            (loop))))))
  (define (pipe-output outp)
    (let-values (((i o) (make-pipe)))
      (thread (lambda () (cat outp o)))
      i))
  (set! server-output (pipe-output server-output))
  (set! server-error  (pipe-output server-error))

which made it a bit better - it won't get stuck, but it looks like it
buffers things in a very weird way - dropping lots of characters,
replacing them with random characters, mixing outputs of several
inputs, lots of fun.  Again, all works perfectly well on 5.8, or (of
course) on Linux.

So -- does anyone know if this is some Solaris bug?  Any other
insights?  I would *really* appreciate any response.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!