Skip to content

Linux write waits 5s after Init failure and lacks libx11 fallback #85

@PekingSpades

Description

@PekingSpades

Background

On Linux/X11, clipboard.Init() establishes the X11 connection. When it fails (e.g. missing DISPLAY or no X server), subsequent calls to clipboard.Write keep blocking for ~5 seconds before returning the same error. Additionally, some distros/containers only ship libx11.so.6, so attempting to load the unversioned libX11.so fails and the package cannot start.

Steps to Reproduce

Write waits 5s after Init failure

  1. Run on Linux without X11 (unset DISPLAY or use a headless container).
  2. Call clipboard.Init(); it returns an error like failed to open display.
  3. Immediately call clipboard.Write(clipboard.FmtText, []byte("test")).
  4. The call blocks for ~5 seconds before returning, even though Init already failed.

Missing libX11.so on systems with only libx11.so.6

  1. Build/run any program using this package on a system that only exposes libx11.so.6.
  2. The program panics during initialization because dlopen("libX11.so") fails.

Actual Behavior

  • clipboard.Write waits the full timeout when Init already reported an error.
  • Systems without the unversioned libX11.so cannot load the package at all.

Expected Behavior

  • Once Init fails, subsequent write/watch calls should immediately return the same error instead of waiting.
  • The loader should fall back to libx11.so.6 so common distros/containers work out of the box.

Proposed Fix

  • Track the Init failure and short-circuit later write/watch calls.
  • Attempt to dlopen("libx11.so.6") if libX11.so is unavailable.

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