Hi all,
Find some code below to reliably cause a rb_sys_fail() for server.rb,
whenever it is run by ruby 1.8.0-previewX on a Linux system (2.2 kernel RH
6.something, 2.4.21-smp kernel RH 7.3, 2.5 kernel debian unstable). The
client can be ran with 1.6.8, still causes rb_sys_fail().
I get normal exceptions/nil-from-gets for Ruby 1.6.8, or when running on
HP-UX. If I run the server with 1.6.8 and the client with 1.8.0-pX, all is
fine, too.
The code below is simplified from my real codebase at work, where the
rb_sys_fail() means the server crashes, without possibility of recovery.
However, I can not take any more code out of these snippets, or the
behaviour goes to normal/desired: exception or nil-from-gets.
Please find the code below, or here:
http://httpd.chello.nl/k.vangelder/ruby/broken_socket.zip
Bye,
Kero.
server.rb
···
require ‘socket’
server = TCPServer.new(‘localhost’, 1357)
while socket = server.accept()
t = Thread.new {
loop {
begin
line = socket.gets
puts line
rescue
end
}
}
i = 0
loop {
socket.puts(“hello”)
sleep 1
i += 1
}
end
client.rb
require 'socket’
require ‘duty’
socket = TCPSocket.new(‘localhost’, 1357)
while line = socket.gets()
puts line
Heavy::duty() # client can be killed (^C at command line) …
socket.puts(“world #{nonexistant}”) # … or will die here,
# either causes crash at server.rb
end
duty.c
#include <ruby.h>
VALUE rb_duty(VALUE module) {
int i, j, k;
for (i=0; i<1000; i++) {
for (j=0; j<1500; j++) { /* lower numbers on slower systems… /
for (k=0; k<2000; k++) {
int nr = ij+k;
}
}
}
return Qnil;
}
void Init_duty() {
VALUE rb_mHeavy = rb_define_module(“Heavy”);
rb_define_module_function(rb_mHeavy, “duty”, rb_duty, 0);
}
extconf.rb
require 'mkmf’
create_makefile(“duty”)