LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-17-2005, 06:55 PM   #1
jwstric2
Member
 
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, 07:25 PM   #2
AltF4
Member
 
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, 07:43 PM   #3
jwstric2
Member
 
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, 05:01 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

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


Reply



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 10:15 AM
Close socket/port THETEZ Linux - General 4 03-28-2004 08:05 PM
P-thread+race condition+mutex+Peterson's algorithm bangla_linux Programming 3 10-29-2003 03:01 AM
Linus Torvalds enters race for California Governor bosewicht Linux - General 2 09-02-2003 12:13 PM
Linus Torvalds enters race for California Governor fancypiper General 10 09-02-2003 12:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 PM.

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