Skip to content

fix: resolve nested IPC socket collisions for instantwmctl#241

Merged
paperbenni merged 1 commit intomainfrom
fix-nested-ipc-socket-2559026827372285636
Mar 20, 2026
Merged

fix: resolve nested IPC socket collisions for instantwmctl#241
paperbenni merged 1 commit intomainfrom
fix-nested-ipc-socket-2559026827372285636

Conversation

@paperbenni
Copy link
Copy Markdown
Member

@paperbenni paperbenni commented Mar 20, 2026

This pull request resolves an issue where running instantwm --backend nested within an existing instantwm session caused instantwmctl to misbehave by clobbering the parent's IPC socket.

  • Dynamic socket path discovery (src/ipc/mod.rs): Instead of hardcoding the socket path to /tmp/instantwm-{uid}.sock and blindly overwriting it, the IPC server now checks for active sockets and intelligently creates sequentially numbered socket paths (/tmp/instantwm-{uid}-1.sock, etc.) when running nested. Dead sockets are still gracefully cleaned up.
  • Client environment priority (src/bin/ctl/ipc.rs): instantwmctl now respects the INSTANTWM_SOCKET environment variable (which is exported by the compositor to its nested clients).

This guarantees proper separation of IPC namespaces between host and nested compositors.


PR created automatically by Jules for task 2559026827372285636 started by @paperbenni

Summary by Sourcery

Ensure IPC sockets are uniquely allocated to avoid collisions between host and nested instantwm instances.

Bug Fixes:

  • Prevent nested instantwm sessions from clobbering the parent compositor's IPC socket.
  • Make instantwmctl connect to the correct compositor by honoring the INSTANTWM_SOCKET environment variable when set.

Summary by CodeRabbit

  • New Features

    • Support for INSTANTWM_SOCKET environment variable to customize socket location.
  • Bug Fixes

    • Improved socket conflict detection and recovery when the default socket is unavailable.

Update `src/ipc/mod.rs` to dynamically find an available socket path
(e.g. `/tmp/instantwm-{uid}-{i}.sock`) rather than blindly removing
and overwriting the default socket. This allows nested instances
of the window manager to maintain their own IPC socket.

Update `src/bin/ctl/ipc.rs` to prioritize the `INSTANTWM_SOCKET`
environment variable when connecting, ensuring `instantwmctl`
connects to the appropriate nested instance when spawned from it.

Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 20, 2026

Reviewer's Guide

Adjusts IPC socket handling so nested instantwm instances use distinct, auto-discovered socket paths and makes instantwmctl prefer the INSTANTWM_SOCKET environment variable for connecting.

Sequence diagram for nested instantwm IPC server socket binding

sequenceDiagram
    actor User
    participant InstantwmParent as Instantwm_parent
    participant InstantwmNested as Instantwm_nested
    participant FS as Filesystem
    participant Env as Environment

    User->>InstantwmParent: start instantwm
    InstantwmParent->>InstantwmParent: IpcServer.bind()
    InstantwmParent->>InstantwmParent: get_available_socket_path()
    loop find first free socket for parent
        InstantwmParent->>FS: check /tmp/instantwm-{uid}.sock exists
        alt does not exist
            InstantwmParent->>InstantwmParent: use base path
        else exists
            InstantwmParent->>FS: connect UnixStream to path
            alt connect fails (dead socket)
                InstantwmParent->>FS: remove_file(path)
                InstantwmParent->>InstantwmParent: use cleaned path
            else connect ok (active server)
                InstantwmParent->>InstantwmParent: i += 1
            end
        end
    end
    InstantwmParent->>FS: bind UnixListener at chosen path
    InstantwmParent->>Env: set_var INSTANTWM_SOCKET=chosen_path

    User->>InstantwmNested: start instantwm --backend nested
    InstantwmNested->>InstantwmNested: IpcServer.bind()
    InstantwmNested->>InstantwmNested: get_available_socket_path()
    loop find next free socket for nested
        InstantwmNested->>FS: check /tmp/instantwm-{uid}.sock or -i.sock exists
        alt socket belongs to parent (active)
            InstantwmNested->>FS: connect UnixStream to path
            InstantwmNested->>InstantwmNested: i += 1
        else dead or missing
            InstantwmNested->>FS: remove dead socket if needed
            InstantwmNested->>InstantwmNested: use this path
        end
    end
    InstantwmNested->>FS: bind UnixListener at nested path
    InstantwmNested->>Env: set_var INSTANTWM_SOCKET=nested_path
Loading

Sequence diagram for instantwmctl IPC socket resolution with environment override

sequenceDiagram
    actor User
    participant Env as Environment
    participant Instantwmctl as Instantwmctl
    participant FS as Filesystem

    User->>Instantwmctl: run instantwmctl command
    Instantwmctl->>Instantwmctl: get_default_socket()
    Instantwmctl->>Env: read INSTANTWM_SOCKET
    alt INSTANTWM_SOCKET is set
        Env-->>Instantwmctl: socket_path_from_env
        Instantwmctl->>Instantwmctl: use socket_path_from_env
    else INSTANTWM_SOCKET not set
        Env-->>Instantwmctl: error
        Instantwmctl->>Instantwmctl: format /tmp/instantwm-{uid}.sock
    end
    Instantwmctl->>FS: connect UnixStream to chosen socket path
    FS-->>Instantwmctl: connection result
    Instantwmctl-->>User: IPC response or error
Loading

File-Level Changes

Change Details Files
Make the IPC server choose a non-conflicting Unix socket path and clean up dead sockets instead of unconditionally overwriting a fixed path.
  • Replace use of a single socket_path() helper with a new get_available_socket_path() in IpcServer::bind to determine the listening Unix socket path.
  • Implement sequential socket name probing based on UID, appending an incrementing suffix when an active socket already exists.
  • Detect and remove stale socket files when a UnixStream::connect to that path fails before binding the listener.
src/ipc/mod.rs
Have the IPC client respect the INSTANTWM_SOCKET environment variable before falling back to the UID-based default path.
  • Update get_default_socket() to first read the INSTANTWM_SOCKET environment variable and return it when set.
  • Retain the previous UID-based /tmp/instantwm-{uid}.sock default when the environment variable is not present.
src/bin/ctl/ipc.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The changes modify socket path handling: the control tool now reads the INSTANTWM_SOCKET environment variable when available, while the IPC server implements dynamic socket path discovery, probing for available paths and setting the environment variable to the selected socket location.

Changes

Cohort / File(s) Summary
Control Tool Socket Resolution
src/bin/ctl/ipc.rs
Added environment variable support: get_default_socket() now checks INSTANTWM_SOCKET before falling back to the default /tmp/instantwm-{geteuid}.sock path.
IPC Server Socket Binding
src/ipc/mod.rs
Replaced static socket path selection with dynamic availability probing. New get_available_socket_path() iteratively checks /tmp/instantwm-{uid}.sock and numbered variants, attempting connections to detect in-use sockets. Removes stale socket files and sets INSTANTWM_SOCKET environment variable to the selected available path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hops skip through /tmp directories,
Finding sockets free and clear,
No two bunnies claim the same—
Probing paths with numbered flair,
Environment whispers the tale,
Where instantwm's warren shall dwell. 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: resolving IPC socket collisions that occur when running nested instantwm instances.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-nested-ipc-socket-2559026827372285636

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@paperbenni paperbenni merged commit 066aae7 into main Mar 20, 2026
4 of 5 checks passed
@paperbenni paperbenni deleted the fix-nested-ipc-socket-2559026827372285636 branch March 20, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant