Skip to content

Using wgpu in a test causes a segfault in WSL #7655

@randomPoison

Description

@randomPoison

Description

Creating a wgpu::Instance in a test causes the test to segfault when the test exits when running in Ubuntu under WSL (Windows subsystem for linux).

Repro steps

Running the following test under WSL triggers the crash:

#[test]
fn inline_test() {
    let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
}

Expected vs observed behavior

I expected I'd be able to run wgpu logic in a regular Rust test, but instead it crashes with a segfault. This doesn't seem to happen under Windows, but it fails when run in WSL.

Extra materials

Output when running cargo test:

     Running unittests src/main.rs (target/debug/deps/main-07cb0cf27c3418f0)

running 1 test
libEGL warning: DRI3: Screen seems not DRI3 capable
libEGL warning: DRI3: Screen seems not DRI3 capable
MESA: error: ZINK: failed to choose pdev
libEGL warning: egl: failed to create dri2 screen
error: test failed, to rerun pass `--bin main`

Caused by:
  process didn't exit successfully: `/home/random/dev/wgpu-gol/target/debug/deps/main-07cb0cf27c3418f0` (signal: 11, SIGSEGV: invalid memory reference)

If I run under GDB and try to get the stacktrace it looks like it's dying under start_thread.

Thread 2 "inline_test" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7c8a6c0 (LWP 8174)]
0x00007fffe1aaab10 in ?? ()
(gdb) bt
#0  0x00007fffe1aaab10 in ?? ()
#1  0x00007ffff7d26340 in __GI___nptl_deallocate_tsd () at ./nptl/nptl_deallocate_tsd.c:73
#2  __GI___nptl_deallocate_tsd () at ./nptl/nptl_deallocate_tsd.c:22
#3  0x00007ffff7d29890 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:455
#4  0x00007ffff7db6c3c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

I tried stepping through it manually to see if I could find out what's happening, seems like the test finishes successfully, i.e. it's not dying in the Instance destructor. Looks like after the test exits we then die in __GI___nptl_deallocate_tsd which is called as part of the cleanup in start_thread.

Platform

  • Dev Environment: Ubuntu 24.024.2 LTS (running under WSL2)
  • Host Environment: Windows 10
  • System Architecture: x86-64
  • wgpu Version: 25.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions