Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've written a TCP server using IO::Socket::INET that opens a socket and listens for new connections. When a connection is accepted, it calls fork() and the child process becomes the "control" process that handles the subsequent input from the filehandle.

Whenever the "control" process reads from the socket, it forks another child, which does some work and then writes a response to the client. What this means is that there may be several separate processes writing to the same filehandle.

The server performs well for awhile, but eventually it gets into a state where it will spawn a "control" process for a new connection, but when the control process spawns in response to a write from the client, the subsequent child process encounters a Bus Error and dies.

The truss output looks like this:

$ truss -pf 18714 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) (sleeping...) 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) = 4 18714: fcntl(4, F_SETFD, 0x00000001) = 0 18714: fork() = 7531 7531: fork() (returning as child ...) = 18714 7531: getpid() = 7531 [18714] 18714: write(1, " 1 8 7 1 4 c o n n e c".., 26) = 26 18714: getcontext(0xFFBEE798) 7531: write(1, "\t 7 5 3 1 c o n t r o".., 27) = 27 18714: getcontext(0xFFBEE660) 18714: close(4) = 0 18714: llseek(4, 0, SEEK_CUR) Err#9 EBADF 18714: close(4) Err#9 EBADF 7531: fstat64(4, 0xFFBEEAA0) = 0 18714: write(1, "\t 1 8 7 1 4 w a i t i".., 33) = 33 7531: brk(0x00B7E000) = 0 7531: ioctl(4, TCGETA, 0xFFBEEA2C) Err#22 EINVAL 7531: read(4, " F r T ; @ 1 8 | $ 9 | S".., 8192) = 215 7531: time() = 1077734297 7531: write(1, " 7 5 3 1 1 0 7 7 7 3 4".., 319) = 319 18714: getcontext(0xFFBEE798) 7531: fork() = 7533 7533: fork() (returning as child ...) = 7531 7533: getpid() = 7533 [7531] 7531: write(1, " 7 5 3 1 f o r k e d ".., 17) = 17 7533: Incurred fault #5, FLTACCESS %pc = 0x00029F18 7533: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7533: Received signal #10, SIGBUS [default] 7533: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7531: time() = 1077734297 7531: write(1, " 7 5 3 1 1 0 7 7 7 3 4".., 114) = 114 7531: Incurred fault #5, FLTACCESS %pc = 0x00029F18 7531: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7531: Received signal #10, SIGBUS [default] 7531: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7531: *** process killed *** 18714: Received signal #18, SIGCLD, in accept() [caught] 18714: siginfo: SIGCLD CLD_KILLED pid=7531 status=0x000A 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) Err#91 ERESTAR +T 18714: waitid(P_ALL, 0, 0xFFBEE548, WEXITED|WTRAPPED) = 0 18714: sigaction(SIGCLD, 0xFFBEE440, 0xFFBEE4C0) = 0 18714: setcontext(0xFFBEE930) 18714: getcontext(0xFFBEE798) 18714: getcontext(0xFFBEE660) 18714: write(1, "\t 1 8 7 1 4 w a i t i".., 33) = 33 18714: getcontext(0xFFBEE798) 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) (sleeping...) 7533: *** process killed ***

Any kind souls out there have advice on what may be causing this and how to fix it? Thanks, Brian

Replies are listed 'Best First'.
Re: Forking server getting Bus Errors
by iburrell (Chaplain) on Feb 25, 2004 at 20:37 UTC
    What operating system? What version of Perl? Can you generate a core file and debug it to find where it is crashing? Are you using any extensions from your code?

    Perl interpreter crashing is a bug in Perl, the operating system, or binary extensions. Binary extensions are frequently a problem area.

Re: Forking server getting Bus Errors
by Anonymous Monk on Feb 25, 2004 at 21:36 UTC
    This is on Solaris 2.7, Perl 5.6.1, nothing fancy just a straight implementation and server. My main question was whether it is a big no-no to have multiple processes writing to the same filehandle...and of course any other suggestions as to what I'm doing wrong.