From: Bill Kelly Date: 2006-03-29T06:11:31+09:00 Subject: Re: timeout when listening with TCPServer From: "Joel VanderWerf" > > I think it might be clearer to write it as > > session = Timeout.timeout 2 do > server.accept > end > > Thread.start(session) do |s| new_connection s end I think I'd do it that way too. (Probably adding a rescue for Timeout::Error.) I wonder if, there's still any possible race condition in this version. session = Timeout.timeout 2 do server.accept # If timeout fires "here" would the socket be leaked? # (eventual probable reaping by GC notwithstanding) end Not that I would lose much sleep over it. But I try to write code without any possibility of race conditions whenever possible. I'm guessing the race condition does exist there. Anyone know whether assignments are atomic with regard to exceptions? E.g. begin Timeout.timeout 2 do session = server.accept # ^^^ atomic? end rescue Timeout::Error end Any possibility of the timeout interrupting the assignment to "session" there? If assignment is atomic then we should be able to avoid leaking the socket. (Just wondering... not too worried about it in practical terms with this particular example.) Regards, Bill