Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-17-2005, 07:55 PM   #1
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
race condition in close socket??

Here's my problem.. Seems to only occur on localhost connections because they happen so fast.

(These are nonblocking sockets by the way)

1. I close a socket after its data transfer
2. Accept another incoming conneciton, it seems to get the same fd as the last socket closed.
3. Set the fd_set
4. Enter select loop which falls through
5. Sometimes though after trying to read or write to this new socket I get a Resouce Not Available.

I took out step 1 and everything seems to work fine.

Any possible idea of whats going on? I have an idea that file descriptor information is not immediately cleaned up. If so how can I prevent this?
Old 03-17-2005, 08:25 PM   #2
Registered: Sep 2002
Location: .at
Distribution: SuSE, Knoppix
Posts: 532

Rep: Reputation: 31
did you do a "shutdown()" on the socket before closing it ?
Old 03-17-2005, 08:43 PM   #3
Registered: Jan 2004
Posts: 105

Original Poster
Rep: Reputation: 15
yes I do actually. as I stated I believe it to be some sort of race condition because remote connections never produce the race condition it seems. I can also put in a small sleep after the close and everything seems to work. This shouldn't happen though I think.
Old 03-18-2005, 06:01 PM   #4
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,580

Rep: Reputation: 191Reputation: 191
So you use close(), shutdown() (which direction?) or both?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel race condition exploit solution jlangelier Slackware 12 01-14-2005 11:15 AM
Close socket/port THETEZ Linux - General 4 03-28-2004 09:05 PM
P-thread+race condition+mutex+Peterson's algorithm bangla_linux Programming 3 10-29-2003 04:01 AM
Linus Torvalds enters race for California Governor bosewicht Linux - General 2 09-02-2003 01:13 PM
Linus Torvalds enters race for California Governor fancypiper General 10 09-02-2003 01:11 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:49 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration