This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: simultaneous socket write/close causes panic?


>>>>> "Grant" == Grant Edwards <grante@visi.com> writes:

    Grant> On Tue, Oct 29, 2002 at 03:30:58PM +0100, Andrew Lunn wrote:
    >> On Tue, Oct 29, 2002 at 12:16:30AM -0800, NavEcos wrote:
    >> > Correct me if I'm wrong (because I might be), but isn't this
    >> > inherently a race condition in the first place?  These seems like an
    >> > application programmer error to me, not an error of eCos.
    >> 
    >> It should not cause a panic. Either the write should succeed, or it
    >> should return an err code saying the file is closed. These operations
    >> should be atomic with respect to each other.

    Grant> Agreed.  

I am not so sure.

If I understand the scenario correctly, the current code does
something like:

  thread a: close(socket_fd);
  thread b: write(socket_fd, buf, size);

Now imagine:

  thread c: new_fd = accept(server_socket);

(calls to connect() or open() would have similar problems).

Depending on what gets scheduled when, the write() may send some or
all of the data out of the first socket, or it may fail with an error
code, or it may write the data to a completely different socket that
happens to reuse the file descriptor and cause all kinds of chaos. Or,
with the particular stack being used, the system panics. Depending on
the application, writing strange data to a random socket could be a
lot more damaging than a panic.

The current application code appears fatally flawed and must be fixed.
A socket is a shared resource, it should only be manipulated by one
thread at a time. If the application is fixed then there is no need to
worry about extra locking in the TCP/IP stack, at least not for this
problem.

Bart

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]