Skip to content

Miri fails when unwinding in safe code #6603

@joseph-gio

Description

@joseph-gio

Bevy version

f7c8eb7

What you did

I created this test:

#[test]
#[should_panic]
fn ub_find() {
    #[derive(Resource, Default)]
    struct SyncCounter(RwLock<()>);

    fn assert_non_sync(counter: Res<SyncCounter>) {
        // Panic if multiple instances of this system try to access `counter` at once.
        let _guard = counter.0.try_write().unwrap();

        // Make sure other systems have a chance to conflict with this one before dropping the guard.
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    let mut world = World::default();
    world.init_resource::<SyncCounter>();

    let mut stage = SystemStage::parallel()
        .with_system(assert_non_sync)
        .with_system(assert_non_sync)
        .with_system(assert_non_sync);

    stage.run(&mut world);
}

What were you expecting

The multiple instances of assert_non_sync should conflict with each other and safely cause a panic.

What went wrong

The following miri failure is triggered: https://github.com/JoJoJet/bevy/actions/runs/3457086747/jobs/5770279259

Additional information

I investigated a bit further on this branch. The test seems to randomly not fail sometimes, but eventually this failure was triggered:

https://github.com/JoJoJet/bevy/actions/runs/3457314695/jobs/5770662745

Some theories from @BoxyUwU https://discord.com/channels/691052431525675048/749335865876021248/1041500126880989184.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorD-ComplexQuite challenging from either a design or technical perspective. Ask for help!P-UnsoundA bug that results in undefined compiler behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions