Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.3.0-dev-01607d73 dead handle 0xbad000000010000 exception #2720

Closed
flavorjones opened this issue Sep 6, 2022 · 5 comments
Closed

22.3.0-dev-01607d73 dead handle 0xbad000000010000 exception #2720

flavorjones opened this issue Sep 6, 2022 · 5 comments
Assignees
Labels
cexts third-party-issue An issue which should be fixed upstream

Comments

@flavorjones
Copy link
Contributor

In the https://github.com/sparklemotion/sqlite3-ruby test suite, we started seeing this error within the past week (between ea16721 (good) and 01607d7 (bad)):

truffleruby: Unexpected internal exception in at_exit,
please report it to https://github.com/oracle/truffleruby/issues.

dead handle 0xbad000000010000 (com.oracle.truffle.api.CompilerDirectives.ShouldNotReachHere)
	from com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere(CompilerDirectives.java:574)
	from com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere(CompilerDirectives.java:5[20](https://github.com/sparklemotion/sqlite3-ruby/runs/8214375961?check_suite_focus=true#step:9:21))
	from org.truffleruby.cext.UnwrapNode$UnwrapNativeNode.raiseError(UnwrapNode.java:98)
	from org.truffleruby.cext.UnwrapNode$UnwrapNativeNode.unwrapTaggedObject(UnwrapNode.java:83)
	from org.truffleruby.cext.UnwrapNodeGen$UnwrapNativeNodeGen.executeAndSpecialize(UnwrapNodeGen.java:378)
	from org.truffleruby.cext.UnwrapNodeGen$UnwrapNativeNodeGen.execute(UnwrapNodeGen.java:334)
	from org.truffleruby.cext.UnwrapNode.longToWrapper(UnwrapNode.java:[27](https://github.com/sparklemotion/sqlite3-ruby/runs/8214375961?check_suite_focus=true#step:9:28)2)
	from org.truffleruby.cext.UnwrapNodeGen.executeAndSpecialize(UnwrapNodeGen.java:1[30](https://github.com/sparklemotion/sqlite3-ruby/runs/8214375961?check_suite_focus=true#step:9:31))
	from org.truffleruby.cext.UnwrapNodeGen.execute(UnwrapNodeGen.java:87)
	from org.truffleruby.cext.ValueWrapperManager$UnwrapperFunction.execute(ValueWrapperManager.java:405)
...

Full log can be found here: https://github.com/sparklemotion/sqlite3-ruby/runs/8214375961?check_suite_focus=true

The version of truffleruby being used in that error run is 22.3.0-dev-01607d73.

About a week earlier, the same sqlite3-ruby commit ran successfully using 22.3.0-dev-ea16721f.

@eregon
Copy link
Member

eregon commented Sep 7, 2022

Thank you for the report. In that commit range, the only change for C extensions is 01607d7.
I think the change for rb_gc_register_address is likely to reveal that issue.
https://github.com/sparklemotion/sqlite3-ruby/blob/6607e64078dd2ee4547e9e82f8aa16efce8ace81/ext/sqlite3/aggregator.c#L268-L269 registers the addresses before assigning them, which is not what TruffleRuby expects.

I will confirm if that guess is indeed the issue.

@eregon eregon self-assigned this Sep 7, 2022
@eregon
Copy link
Member

eregon commented Sep 7, 2022

It's already clear from the stacktrace actually:

/home/eregon/code/sqlite3-ruby/ext/sqlite3/aggregator.c:240:in `rb_sqlite3_define_aggregator2'
	from /home/eregon/.rubies/truffleruby-dev/lib/truffle/truffle/cext_ruby.rb:41:in `define_aggregator2'
	from /home/eregon/code/sqlite3-ruby/lib/sqlite3/database.rb:493:in `create_aggregate'
	from /home/eregon/code/sqlite3-ruby/test/test_integration_aggregate.rb:26:in `test_create_aggregate_without_block'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest/test.rb:98:in `block (3 levels) in run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest/test.rb:195:in `capture_exceptions'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest/test.rb:95:in `block (2 levels) in run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:296:in `time_it'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest/test.rb:94:in `block in run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:391:in `on_signal'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest/test.rb:243:in `with_info_handler'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest/test.rb:93:in `run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:1059:in `run_one_method'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:365:in `run_one_method'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:352:in `block (2 levels) in run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:351:in `each'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:351:in `block in run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:391:in `on_signal'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:378:in `with_info_handler'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:350:in `run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:182:in `block in __run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:182:in `map'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:182:in `__run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:159:in `run'
	from /home/eregon/.rubies/truffleruby-dev/lib/gems/gems/minitest-5.16.2/lib/minitest.rb:83:in `block in autorun'

https://github.com/sparklemotion/sqlite3-ruby/blob/6607e64078dd2ee4547e9e82f8aa16efce8ace81/ext/sqlite3/aggregator.c#L240

eregon added a commit to eregon/sqlite3-ruby that referenced this issue Sep 7, 2022
* Otherwise the GC might read the variable when it is not pointing
  to a Ruby object yet.
* TruffleRuby also assumes it can read the pointer when
  rb_gc_register_address() is called: oracle/truffleruby#2720
@eregon eregon added the third-party-issue An issue which should be fixed upstream label Sep 7, 2022
@eregon
Copy link
Member

eregon commented Sep 7, 2022

Fix: sparklemotion/sqlite3-ruby#345

@eregon eregon closed this as completed Sep 7, 2022
@eregon
Copy link
Member

eregon commented Sep 7, 2022

We should fix these TODOs though, I'll create an issue for that => #2721:

void rb_gc_register_address(VALUE *address) {
/* TODO: This should guard the address of the pointer, not the
object pointed to, but we haven't yet found a good way to implement
that, or a real world use case where it is required. */
polyglot_invoke(RUBY_CEXT, "rb_gc_register_address", address, rb_tr_unwrap(*address));
}

void rb_global_variable(VALUE *obj) {
/* TODO: This should guard the address of the pointer, not the
object pointed to, but we haven't yet found a good way to implement
that, or a real world use case where it is required. */
RUBY_CEXT_INVOKE_NO_WRAP("rb_global_variable", *obj);
}

@flavorjones
Copy link
Contributor Author

Thanks for investigating, and for the upstream PR.

flavorjones pushed a commit to sparklemotion/sqlite3-ruby that referenced this issue Sep 7, 2022
…ed (#345)

rb_gc_register_address() must be called after the variable was assigned. Otherwise the GC might read the variable when it is not pointing to a Ruby object yet. TruffleRuby also assumes it can read the pointer when rb_gc_register_address() is called: oracle/truffleruby#2720

* Prefer rb_gc_register_mark_object() since the variable is never reassigned
* Mark immediately after assigning the variable to prevent the VALUE to move by GC compaction on CRuby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cexts third-party-issue An issue which should be fixed upstream
Projects
None yet
Development

No branches or pull requests

2 participants