Forum: Ruby cross-thread violation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
rakaur (Guest)
on 2006-02-17 01:20
(Received via mailing list)
/usr/local/lib/ruby/1.8/monitor.rb:218: [BUG] cross-thread violation on
rb_thread_schedule()
ruby 1.8.4 (2005-12-24) [i386-freebsd4]

Abort trap (core dumped)

$ gdb `which ruby` ruby.core
GNU gdb 4.18 (FreeBSD)
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i386-unknown-freebsd"...(no debugging
symbols found)...
Core was generated by `ruby'.
Program terminated with signal 6, Abort trap.
Reading symbols from /usr/local/lib/libruby18.so.18...(no debugging
symbols found)...done.
Reading symbols from /usr/lib/libcrypt.so.2...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libm.so.2...(no debugging symbols
found)...done.
Reading symbols from /usr/lib/libc_r.so.4...(no debugging symbols
found)...done.
Reading symbols from
/usr/local/lib/ruby/site_ruby/1.8/i386-freebsd4/idn.so...
(no debugging symbols found)...done.
Reading symbols from /usr/local/lib/libidn.so.16...(no debugging
symbols found)...done.
Reading symbols from /usr/local/lib/libgnugetopt.so.1...(no debugging
symbols found)...done.
Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging
symbols found)...done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/stringio.so...(no debugging
symbols found)...
done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/syck.so...(no debugging symbols
found)...done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/socket.so...(no debugging symbols
found)...done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/digest/md5.so...(no debugging
symbols found)...
done.
Reading symbols from /usr/local/lib/libcrypto.so.4...(no debugging
symbols found)...done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/digest.so...(no debugging symbols
found)...done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/fcntl.so...(no debugging symbols
found)...done.
Reading symbols from
/usr/local/lib/ruby/1.8/i386-freebsd4/openssl.so...(no debugging
symbols found)...done.
Reading symbols from /usr/local/lib/libssl.so.4...(no debugging symbols
found)...done.
Reading symbols from /usr/local/lib/ruby/1.8/i386-freebsd4/nkf.so...(no
debugging symbols found)...done.
Reading symbols from /usr/libexec/ld-elf.so.1...(no debugging symbols
found)...done.
#0  0x2819b584 in kill () from /usr/lib/libc_r.so.4
(gdb) bt
#0  0x2819b584 in kill () from /usr/lib/libc_r.so.4
#1  0x281e9b9e in abort () from /usr/lib/libc_r.so.4
#2  0x2808333d in rb_bug () from /usr/local/lib/libruby18.so.18
#3  0x280990c6 in rb_thread_schedule () from
/usr/local/lib/libruby18.so.18
#4  0x2809a678 in rb_thread_pass () from /usr/local/lib/libruby18.so.18
#5  0x280908c1 in rb_call0 () from /usr/local/lib/libruby18.so.18
#6  0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#7  0x2808b5ff in rb_eval () from /usr/local/lib/libruby18.so.18
#8  0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#9  0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#10 0x2808b8a4 in rb_eval () from /usr/local/lib/libruby18.so.18
#11 0x2808ae10 in rb_eval () from /usr/local/lib/libruby18.so.18
#12 0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#13 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#14 0x2808b5ff in rb_eval () from /usr/local/lib/libruby18.so.18
#15 0x2808a732 in rb_eval () from /usr/local/lib/libruby18.so.18
#16 0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#17 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#18 0x2808b5ff in rb_eval () from /usr/local/lib/libruby18.so.18
#19 0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#20 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#21 0x2808b82c in rb_eval () from /usr/local/lib/libruby18.so.18
#22 0x280964e9 in block_pass () from /usr/local/lib/libruby18.so.18
#23 0x2808a560 in rb_eval () from /usr/local/lib/libruby18.so.18
#24 0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#25 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#26 0x2808b5ff in rb_eval () from /usr/local/lib/libruby18.so.18
#27 0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#28 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#29 0x2808b5ff in rb_eval () from /usr/local/lib/libruby18.so.18
#30 0x28090f40 in rb_call0 () from /usr/local/lib/libruby18.so.18
#31 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#32 0x2808b8a4 in rb_eval () from /usr/local/lib/libruby18.so.18
#33 0x2808ea1f in rb_yield_0 () from /usr/local/lib/libruby18.so.18
#34 0x28095e7c in proc_invoke () from /usr/local/lib/libruby18.so.18
#35 0x28096002 in proc_call () from /usr/local/lib/libruby18.so.18
#36 0x28090892 in rb_call0 () from /usr/local/lib/libruby18.so.18
#37 0x280913d0 in rb_call () from /usr/local/lib/libruby18.so.18
#38 0x28091801 in rb_funcall2 () from /usr/local/lib/libruby18.so.18
#39 0x28087b11 in rb_eval_cmd () from /usr/local/lib/libruby18.so.18
#40 0x28097ed2 in run_trap_eval () from /usr/local/lib/libruby18.so.18
#41 0x2808fb1a in rb_protect () from /usr/local/lib/libruby18.so.18
#42 0x280980a5 in rb_trap_eval () from /usr/local/lib/libruby18.so.18
#43 0x2809b7ad in rb_thread_trap_eval () from
/usr/local/lib/libruby18.so.18
#44 0x280eab45 in signal_exec () from /usr/local/lib/libruby18.so.18
#45 0x280eab92 in sighandler () from /usr/local/lib/libruby18.so.18
#46 0x281ad723 in _thread_sig_handler () from /usr/lib/libc_r.so.4
#47 0x281ae9bc in _thread_sig_wrapper () from /usr/lib/libc_r.so.4
#48 0x0 in ?? ()
(gdb)

Seems like a stack overflow, but I can't seem to figure what's doing it.
unknown (Guest)
on 2006-02-17 02:15
(Received via mailing list)
On Friday 17 February 2006 08:18 am, rakaur wrote:

Heh, well okay. I received the exact same error on NetBSD 2.0.2
yesterday
afternoon when I was working on a project. I still have the core and
tells
similar information. Though, I'm using Ruby 1.8.3, I'm surprised the bug
hasn't been ran in to before, especially since portupgrade in FreeBSD
ports
is completely ruby based.

Tsume
rakaur (Guest)
on 2006-02-17 02:45
(Received via mailing list)
Apparently this was caused when I did something along the lines of.

Thread.new do
    Timeout.new....
    ....
end

Timeout.new was a typo, should have been Timeout::timeout. I don't know
why this
completely killed the interpreter though.
Yukihiro M. (Guest)
on 2006-02-17 04:55
(Received via mailing list)
Hi,

In message "Re: cross-thread violation"
    on Fri, 17 Feb 2006 09:43:28 +0900, "rakaur" 
<removed_email_address@domain.invalid>
writes:

|Apparently this was caused when I did something along the lines of.
|
|Thread.new do
|    Timeout.new....
|    ....
|end
|
|Timeout.new was a typo, should have been Timeout::timeout. I don't know
|why this
|completely killed the interpreter though.

It is possible to show us a script to reproduce your problem?

							matz.
rakaur (Guest)
on 2006-02-17 10:04
(Received via mailing list)
require 'timeout'

Thread.new do
    begin
        Timeout.new(10) do
            sleep(11)
        end
    rescue Timeout::Error
        puts "trying again"
        retry
    end
end

loop { sleep(1) }

This kills it on FreeBSD 4.11, but not on Linux 2.6.13. Note that
"Timeout.new" is invalid, but that's how I got it to do it in the first
place.

I was trying to make use of Timeouts to do a hacky timer system (eg, a
block that's run every N seconds). I figured by doing:

Thread.new do
    begin
        Timeout::timeout(N) { sleep(N + 1) }
    rescue Timeout::Error
        # some code to run every N seconds
        retry
    end
end

I could accomplish that. By making the mistake Timeout.new instead of
Timeout::timeout is how I originally caused this to happen. After
changing it to Timeout::timeout it does work as I intended.
rakaur (Guest)
on 2006-02-17 10:10
(Received via mailing list)
Sorry, I should clarify "kills it." It doesn't actually kill the
interpreter until I issue SIGINT, or ^C. When it gets the iterrupt, it
dumps core with "abort trap."
This topic is locked and can not be replied to.