TCPServer' s accept method crashes the ruby program

Operating System: Windows XP
Ruby Version: ruby 1.9.2p290 (2011-07-09) [i386-mingw32]

Program for TCPServer:

require “socket”
Thread.abort_on_exception = true
dts = TCPServer.new(‘localhost’, 20000)
begin
loop do
puts" Inside the Loop to accept Client Request #{dts}"
Thread.start(dts.accept_nonblock) do |s|
print(s, " is accepted\n")
print(s, " is accepted\n")
s.write(Time.now)
print(s, " is gone\n")
s.close
end

end
end

Output while running this on WindowsXP Operating system

C:\Documents and Settings\verma.r\My Documents\RubyTest>ruby server.rb
Inside the Loop to accept Client Request #TCPServer:0x11cf8c8
C:\Documents and Settings\verma.r\My Documents\RubyTest>ruby server.rb

Problem:

After printing the first puts" Inside the Loop to accept Client Request
#{dts}". The programs crashed in Thread.start(dts.accept_nonblock)
without even using any client to connect to server.

This program is working on some PC and gives this error on other.
Has anyone experienced the same problem before. What can be region for
the crash please suggest.

Thanks

On Mon, Nov 28, 2011 at 6:55 PM, mohit b. [email protected]
wrote:

loop do
puts" Inside the Loop to accept Client Request #{dts}"
Thread.start(dts.accept_nonblock) do |s|

You do not want to accept nonblocking in this way here. The accepting
thread can block without problems as it does not have to do anything
apart from accepting connections - you have your worker threads for
client handling.

Output while running this on WindowsXP Operating system
without even using any client to connect to server.
What exactly does “crashes” mean? Core dump? Simple exit? Any error
messages?

This program is working on some PC and gives this error on other.
Has anyone experienced the same problem before. What can be region for
the crash please suggest.

Different timing may have dramatic effects. I am not yet convinced
that it actually crashes.

Please provide more details.

Kind regards

robert

Same problem occurs when Webrick server starts . In below code :

def accept_client(svr)
puts “Inside accept_client1”
sock = nil
puts “svr = #{svr}”
begin
puts “Inside accept_client2”
sock = svr.accept
puts “sock = #{sock}”
sock.sync = true
Utils::set_non_blocking(sock)
Utils::set_close_on_exec(sock)
rescue Errno::ECONNRESET, Errno::ECONNABORTED,
Errno::EPROTO, Errno::EINVAL => ex
rescue Exception => ex
msg = “#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}”
@logger.error msg
end
return sock
end

prints are coming till “Inside accept_client2”. The value of svr is
object of TCPServer. But no prints appear for sock as server dies on
reaching svr.accept.

Please suggest why this is happening while same code is working on other
machines

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs