CertainLach/jrsonnet

assertion failed on Winodws x86 in debug mode

messense opened this issue · 6 comments

https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133

stacktrace:

thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `2`,
 right: `1`', C:\Users\runneradmin\.cargo\git\checkouts\jrsonnet-22393f555b7197c5\153383c\crates\jrsonnet-interner\src\lib.rs:88:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `2`,
 right: `1`', C:\Users\runneradmin\.cargo\git\checkouts\jrsonnet-22393f555b7197c5\153383c\crates\jrsonnet-interner\src\lib.rs:88:17
stack backtrace:
   0: 0x7423844a - core::fmt::write
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\core\src\fmt\mod.rs:1213
   1: 0x7421d871 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\io\mod.rs:1682
   2: 0x74220d15 - std::sys_common::backtrace::_print
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\sys_common\backtrace.rs:47
   3: 0x74220d15 - std::sys_common::backtrace::print
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\sys_common\backtrace.rs:34
   4: 0x74222c87 - std::panicking::default_hook::closure$1
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\panicking.rs:267
   5: 0x742228c9 - std::panicking::default_hook
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\panicking.rs:286
   6: 0x74223465 - std::panicking::rust_panic_with_hook
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\panicking.rs:688
   7: 0x74223225 - std::panicking::begin_panic_handler::closure$0
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\panicking.rs:579
   8: 0x7422188a - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\sys_common\backtrace.rs:137
   9: 0x74222ea4 - std::panicking::begin_panic_handler
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\panicking.rs:575
  10: 0x7423fc4f - core::panicking::panic_fmt
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\core\src\panicking.rs:64
  11: 0x7423ffd7 - core::panicking::assert_failed_inner
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\core\src\panicking.rs:258
  12: 0x74206ba9 - core::panicking::assert_failed<u32,u32>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\panicking.rs:212
  13: 0x741f1e28 - jrsonnet_interner::impl$6::drop
                       at C:\Users\runneradmin\.cargo\git\checkouts\jrsonnet-22393f555b7197c5\153383c\crates\jrsonnet-interner\src\lib.rs:93
  14:   0xbedf04 - <unknown>
  15: 0x7419176f - core::ptr::drop_in_place<enum2$<core::option::Option<jrsonnet_interner::IStr> > >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  16: 0x740c07d8 - core::ptr::drop_in_place<jrsonnet_evaluator::FileData>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  17: 0x740c3fbd - core::ptr::drop_in_place<tuple$<jrsonnet_parser::source::SourcePath,jrsonnet_evaluator::FileData> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  18: 0x7415d76b - core::ptr::mut_ptr::impl$0::drop_in_place
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mut_ptr.rs:1451
  19: 0x7415d76b - hashbrown::raw::Bucket<tuple$<jrsonnet_parser::source::SourcePath,jrsonnet_evaluator::FileData> >::drop<tuple$<jrsonnet_parser::source::SourcePath,jrsonnet_evaluator::FileData> >
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba1[50](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:51)01f\hashbrown-0.13.2\src\raw\mod.rs:344
  20: 0x7415c659 - hashbrown::raw::impl$16::drop<tuple$<jrsonnet_parser::source::SourcePath,jrsonnet_evaluator::FileData>,hashbrown::raw::alloc::inner::Global>
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\hashbrown-0.13.2\src\raw\mod.rs:1874
  21: 0x740bf8fd - core::ptr::drop_in_place<hashbrown::map::HashMap<jrsonnet_parser::source::SourcePath,jrsonnet_evaluator::FileData,core::hash::BuildHasherDefault<rustc_hash::FxHasher>,hashbrown::raw::alloc::inner::Global> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  22: 0x740bf04d - core::ptr::drop_in_place<core::cell::UnsafeCell<jrsonnet_evaluator::gc::GcHashMap<jrsonnet_parser::source::SourcePath,jrsonnet_evaluator::FileData> > >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  23: 0x740c2115 - core::ptr::drop_in_place<jrsonnet_evaluator::EvaluationStateInternals>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  24: 0x740915dd - core::mem::manually_drop::ManuallyDrop<jrsonnet_evaluator::EvaluationStateInternals>::drop<jrsonnet_evaluator::EvaluationStateInternals>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\mem\manually_drop.rs:144
  25: 0x7412cf65 - jrsonnet_gcmodule::cc::drop_ccbox<jrsonnet_evaluator::EvaluationStateInternals,jrsonnet_gcmodule::collect::ObjectSpace>
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\cc.rs:559
  26: 0x7413ccd5 - jrsonnet_gcmodule::cc::impl$17::drop<jrsonnet_evaluator::EvaluationStateInternals,jrsonnet_gcmodule::collect::ObjectSpace>
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\cc.rs:583
  27: 0x740bec0d - core::ptr::drop_in_place<jrsonnet_gcmodule::cc::RawCc<jrsonnet_evaluator::EvaluationStateInternals,jrsonnet_gcmodule::collect::ObjectSpace> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  28:   0xbee11c - <unknown>
  29: 0x741ffba8 - core::ptr::drop_in_place<slice2$<alloc::boxed::Box<dyn$<jrsonnet_gcmodule::cc::GcClone>,alloc::alloc::Global> > >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  30: 0x74201c89 - alloc::vec::impl$27::drop<alloc::boxed::Box<dyn$<jrsonnet_gcmodule::cc::GcClone>,alloc::alloc::Global>,alloc::alloc::Global>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\alloc\src\vec\mod.rs:3059
  31: 0x741fe686 - jrsonnet_gcmodule::collect::release_unreachable<jrsonnet_gcmodule::collect::GcHeader,tuple$<> >
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\collect.rs:436
  32: 0x741fe686 - jrsonnet_gcmodule::collect::release_unreachable<jrsonnet_gcmodule::collect::GcHeader,tuple$<> >
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\collect.rs:436
  33: 0x741fda8d - jrsonnet_gcmodule::collect::collect_list<jrsonnet_gcmodule::collect::GcHeader,tuple$<> >
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\collect.rs:274
  34: 0x741fd760 - jrsonnet_gcmodule::collect::ObjectSpace::collect_cycles
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\collect.rs:155
  35: 0x741fd7bd - jrsonnet_gcmodule::collect::impl$3::drop
                       at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jrsonnet-gcmodule-0.3.5\src\collect.rs:179
  36: 0x741ffb33 - core::ptr::drop_in_place<enum2$<core::option::Option<jrsonnet_gcmodule::collect::ObjectSpace> > >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  37: 0x741ff70d - core::ptr::drop_in_place<std::thread::local::lazy::LazyKeyInner<jrsonnet_gcmodule::collect::ObjectSpace> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  38: 0x741ff818 - core::ptr::drop_in_place<alloc::boxed::Box<std::thread::local::os::Value<jrsonnet_gcmodule::collect::ObjectSpace>,alloc::alloc::Global> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  39: 0x741ffb33 - core::ptr::drop_in_place<enum2$<core::option::Option<jrsonnet_gcmodule::collect::ObjectSpace> > >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  40: 0x741ff70d - core::ptr::drop_in_place<std::thread::local::lazy::LazyKeyInner<jrsonnet_gcmodule::collect::ObjectSpace> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  41: 0x741ff818 - core::ptr::drop_in_place<alloc::boxed::Box<std::thread::local::os::Value<jrsonnet_gcmodule::collect::ObjectSpace>,alloc::alloc::Global> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\core\src\ptr\mod.rs:490
  42: 0x74202a[51](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:52) - std::thread::local::os::destroy_value::closure$0<jrsonnet_gcmodule::collect::ObjectSpace>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\std\src\thread\local.rs:1149
  43: 0x74202c4d - std::panicking::try::do_call<std::thread::local::os::destroy_value::closure_env$0<jrsonnet_gcmodule::collect::ObjectSpace>,tuple$<> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\std\src\panicking.rs:483
  44: 0x74202bcf - std::panicking::try<tuple$<>,std::thread::local::os::destroy_value::closure_env$0<jrsonnet_gcmodule::collect::ObjectSpace> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\std\src\panicking.rs:447
  45: 0x74202804 - std::thread::local::os::destroy_value<jrsonnet_gcmodule::collect::ObjectSpace>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\std\src\thread\local.rs:1145
  46: 0x74202bcf - std::panicking::try<tuple$<>,std::thread::local::os::destroy_value::closure_env$0<jrsonnet_gcmodule::collect::ObjectSpace> >
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\std\src\panicking.rs:447
  47: 0x74202804 - std::thread::local::os::destroy_value<jrsonnet_gcmodule::collect::ObjectSpace>
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d\library\std\src\thread\local.rs:1145
  48: 0x742272be - std::sys::windows::thread_local_key::run_dtors
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\sys\windows\thread_local_key.rs:277
  49: 0x742272be - std::sys::windows::thread_local_key::on_tls_callback
                       at /rustc/5e37043d63bfe2f3be8fa5a05b07d6c0dad5775d/library\std\src\sys\windows\thread_local_key.rs:244
  50: 0x7789af69 - LdrHotPatchNotify
  51: 0x77883be6 - LdrDeleteEnclave
  [52](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:53): 0x7786714e - RtlDeactivateActivationContextUnsafeFast
  [53](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:54): 0x778672a3 - RtlDeactivateActivationContextUnsafeFast
  [54](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:55): 0x778678cd - LdrShutdownProcess
  [55](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:56): 0x7786a925 - RtlExitUserProcess
  [56](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:57): 0x76bc8e93 - ExitProcess
  [57](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:58): 0x76536244 - exit
  [58](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:59): 0x76536171 - exit
  [59](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:60):   0x701266 - <unknown>
  [60](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:61): 0x76bb6a39 - BaseThreadInitThunk
  [61](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:62): 0x77877d1d - RtlGetFullPathName_UEx
  [62](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:63): 0x[77](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:78)[87](https://github.com/messense/rjsonnet-py/actions/runs/3982495683/jobs/6827010133#step:6:88)7ceb - RtlGetFullPathName_UEx
thread panicked while panicking. aborting.

debug_assert_eq!(Inner::strong_count(inner), 1);

Fixed in 45d6bc3

Not sure why, but the failure still occurs after updating to 45d6bc3

https://github.com/messense/rjsonnet-py/actions/runs/3992204250/jobs/6847834754

There was yet another stacked borrows rule violation in jrsonnet-interner (5acdbdb)
This probably shouldn't be the case, as stacked borrow rules are not yet enforced, but I have no idea what else it can be.

This probably shouldn't be the case, as stacked borrow rules are not yet enforced, but I have no idea what else it can be.

Yep, still happens: https://github.com/messense/rjsonnet-py/actions/runs/4029605949/jobs/6927660508

Not a big deal since it won't be triggered in release mode, at worst it leaks some memory.

There might be some worse issue causing this, however I have no idea why it may only fail on windows x32

Figured out this issue.
It can be explained by this line in LocalKey docs:

https://doc.rust-lang.org/std/thread/struct.LocalKey.html#platform-specific-behavior

On all platforms it’s possible for TLS to re-initialize other TLS slots during destruction. Some platforms ensure that this cannot happen infinitely by preventing re-initialization of any slot that has been destroyed, but not all platforms have this guard. Those platforms that do not guard typically have a synthetic limit after which point no more destructors are run.

What happens here is during process destruction, instead of failing on the try_with call, storage is re-initialized and isn't cleaned this time.

Unfortunately, this means #113 is unrelated to this failure, and something else is wrong somewhere.

Regarding this bug - I only see this behaviour can only be replaced with a leak because LocalKey doesn't allow us to introspect somehow if the value is already being destroyed to allow it to clean itself up safely. Better implementation may be possible with the nightly-only #[thread_local] attribute here, but I don't see any gains from it here.