Closing a socket.
Till Straumann
strauman at slac.stanford.edu
Thu May 12 01:23:27 UTC 2005
Thomas Rauscher wrote:
>
>
>
>
>
>>-----Original Message-----
>>From: Chris Johns [mailto:chrisj at rtems.org]
>>Sent: Wednesday, May 11, 2005 2:34 AM
>>To: RTEMS Users
>>Subject: Closing a socket.
>>
>>Hello,
>>
>>Can a socket be closed by one thread while another thread is
>>blocked in the socket (soconnsleep) ?
>>
>>If not does a way exist to wake the blocked thread or should
>>the thread be deleted before closing the socket ?
>>
>>
>>
>
>Maybe there is a race condition (visual check against 4.6.2).
>Please correct me if I'm wrong.
>
I agree. It's not OK to close a socket another thread is blocked on.
Besides so->so_pgid, the surrounding/calling syscall (accept, ...)
also accesses the already released socket struct.
OTOH, deleting a blocked thread doesn't seem like a good solution either
--> I believe the rtems syscalls should be changed to make it safe to
close a socket on which another thread is blocking. This could be achieved
e.g., by letting soconnsleep/soconnwakeup use different events if the
socket is being closed and propagating an error code that prevents
the socket structure being from accessed from the RTEMS glue code
in this case.
-- Till
>
>If rtems_bsdnet_close is called, the socket is freed in
>soclose (depends on socket state, protocol used, ...).
>The waiting thread might wake up later (depends on
>scheduling) and could access so->so_pgid in soconnsleep().
>Bad things would happen if this memory area is now
>used for something else...
>I remember having seen this in an accept/close race
>(rtems 4.5).
>
>A clean (and portable) way is to send a
>"QUIT" message to the socket so that the blocking
>thread can stop using the socket.
>
>TCP connections can be closed with shutdown().
>
>Regards,
>Thomas Rauscher
>
>--
>Thomas Rauscher
>LOYTEC electronics GmbH
>
>
>
More information about the users
mailing list