Skip to content

[BUG] Unsafe std::env::remove_var in WSL2 workaround #895

Description

@rajpreetcodes

Bug Report

Platform

Linux (WSL2 specifically), potentially macOS

Current Behavior

In apps/desktop/src/main.rs:28-30, the code uses unsafe { std::env::remove_var("WAYLAND_DISPLAY") } to work around a GPUI 0.2.2 WSLg issue:

unsafe {
    std::env::remove_var("WAYLAND_DISPLAY");
}

Problems

  1. Thread-safety violation: std::env::remove_var is NOT thread-safe. If any other thread reads the environment concurrently (common in async runtimes), this causes undefined behavior.
  2. Fragile assumption: The comment claims "this is the first statement in main" but any future code added above breaks this guarantee.
  3. Process-wide side effect: Modifies environment for the entire process, affecting child processes and other threads.

Expected Behavior

Use thread-safe alternatives:

  • std::env::set_var("WAYLAND_DISPLAY", "") to unset (still not fully thread-safe but safer)
  • Or better: configure the GPUI/Winit window builder to use X11 explicitly via WAYLAND_DISPLAY="" cargo run at process spawn
  • Or set the env var before spawning the process via Command::env_remove("WAYLAND_DISPLAY")

Steps To Reproduce

  1. Run on WSL2 with both X11 and Wayland configured
  2. App may crash or behave unpredictably under concurrent env access

Recurrence Probability

Sometimes - race condition dependent

Additional Context

This is a soundness issue in Rust. The unsafe block doesn't actually make the operation safe - it just tells the compiler you've verified safety, which isn't true here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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