nondeterministic results from accept()

nondeterministic results from accept()

Post by Kevin F. We » Sun, 17 Nov 1996 04:00:00



Earlier this week I posted a question concerning a server process that had
to be connected to twice by the client to get read()s and write()s going
properly. Andrerw Gierth was kind enough to respond with a couple of
suggestions that ultimately led me to find out what was wrong, but now I want
to know why!

Here is what happens:
the client  connect()s with the server,
the server accept()s the client,
the server does a read( client_sock...) returns 0 && errno = 0,
the server does a write to the client,
the server goes into another read( client_sock, ... ) returns 0 && errno = EBADFthe server returns to accept() loop,
I SIGQUIT the client,
Immediately re-invoke the client, and connect successfully until the client
        ends the session.

This behaviour is the same when I telnet to the host and port. First time
nada, second time the read()s and write()s go as expected.

To correct this behaviour I changed the line of code that had my accept()
statement:
OLD-> if ( client = accept( server_sock, ...  ) == -1 )
         take care of error;
      else
             continue on fork() child to handle session...

NEW->  client = accept( server_sock, ... );
           if ( client == -1 )
                  take care of error
       else
          continue on, fork() child to handle session...

Why doesn't it work the first time in the composite if() statement? I have
had one answer so far that suspected this was an artifact of compiler
optimization. The platforms this code has run on are DEC Alphas, and a
Pentium and 486x running different flavors of Solaris 2.x.

Thanks,
KFW
-

-
sig schmig

 
 
 

nondeterministic results from accept()

Post by Andrew Gier » Mon, 18 Nov 1996 04:00:00


 Kevin> Earlier this week I posted a question concerning a server
 Kevin> process that had to be connected to twice by the client to get
 Kevin> read()s and write()s going properly. Andrerw Gierth was kind
 Kevin> enough to respond with a couple of suggestions that ultimately
 Kevin> led me to find out what was wrong, but now I want to know why!

And here I am again...

 Kevin> [snip]

 Kevin> To correct this behaviour I changed the line of code that had my
 Kevin> accept() statement:

 OLD-> if ( client = accept( server_sock, ...  ) == -1 )
            ^                                  ^
            \- need brackets around this bit --/

This is the error known as the 'precedence screw'. The assignment operators
have very low precedence, so the above expression is equivalent to:

            client = (accept(...) == -1)

which will set client to 1 if the accept fails, and 0 if it succeeded.

You were finding that the *second* connection worked because:

First accept:
  accept returns a new socket
  client gets set to 0 (standard input)
  read fails
  you close descriptor 0
Second accept:
  accept returns 0 as the new socket (first available FD)
  client gets set to 0
  everything works...

Hope this clarifies things...

--

"Ceterum censeo Microsoftam delendam esse" - Alain Knaff in nanam

 
 
 

1. Nondeterministic behaviour in 2.3


: Over the last weeks I've seen nondeterministic behaviour with respect to
: runtime in both Solaris 2.2 and 2.3 that is very annoying. Now I think I
: found a way to reproduce it, but I still can't fix it.

: I have a small application that usually takes 1.2s to complete, but under
: certain conditions it takes (again reproducably[%]) up to 17s, without any
: visible load on the machine. The machine is a SS1000 with four processors,
: and 128Mbytes of main memory. It also happens on a SS10/51 with 2 CPUs.

Somebody suggested that I install the jumbo kernel patch 101318-32,
which I did. Now the single-threaded version of my application takes
more than twice as long, while the multithreaded became slower by a
factor of 1.5.

I confirmed with gprof and tcov that this is not a non-deterministic
effect of my application, but definitely of the operating system or
the hardware.

Any ideas, help, condolences?

Arne

2. PATCH: fix fd_mcs build for scsi changes, mca compt

3. AHA 1542 -unexpected/nondeterministic behavior -SUMMARY

4. Ethernet and SLIP problem

5. how to make the linux accept 8-bit?

6. globbing question

7. accept()-like wait for semaphore AND socket?

8. World Wide Free Internet Access .

9. asynchronous listen/accept

10. Apache error_log: socket error: accept failed

11. SNMP : Accept access only from ...

12. can unix rpc procedure accept more than one parameter

13. accept() faild in CERN httpd-3.0(In HTDaemon.c)