Skip to content

linux/x11: Don't stop worker thread if handling selection request fails#186

Merged
complexspaces merged 2 commits into1Password:masterfrom
crumblingstatue:x11-clipboard-stay-alive
Jun 24, 2025
Merged

linux/x11: Don't stop worker thread if handling selection request fails#186
complexspaces merged 2 commits into1Password:masterfrom
crumblingstatue:x11-clipboard-stay-alive

Conversation

@crumblingstatue
Copy link
Contributor

@crumblingstatue crumblingstatue commented Jun 7, 2025

Just because one request fails, that doesn't mean we can't handle subsequent requests.
Stopping the worker thread on failure means that every subsequent request will fail, which is usually undesirable.

Unresolved questions

I don't know if this has any undesirable side effects, since I'm not an X11/clipboard expert.
This requires careful review.

  • Should we have some kind of way to programmatically get the error, rather than logging it?

Just because one request fails, that doesn't mean we can't handle
subsequent requests.
Stopping the worker thread on failure means that every subsequent
request will fail, which is usually undesirable.
@complexspaces
Copy link
Member

Hey there, thanks for the PR. I like this idea overall. Out of curiosity do you have any additional context or examples of where this helps in the wild?

I went through handle_selection_request to look at what errors it deals with and everything seems to come from the X11 connection's fallibility. Looking at the error types and upstream documentation, it seems like most of the enum variants are fatal? I'm not an X11 expert but my reading is that anything prefixed with XCB_CONN_ means future requests won't work again because the server has closed our socket. Does that match up with your understanding?

Given that, these seem like the only errors we are able to ignore during operations:

  • UnknownError
  • IoError

Should we have some kind of way to programmatically get the error, rather than logging it?

As much as I would like that the current architecture of the X11 clipboard doesn't support that. The background thread isn't owned by any specific Clipboard instance, so without a lot more global state (and bookkeeping) I don't see how we can cleanly pass an error from a specific .set() call.

@crumblingstatue
Copy link
Contributor Author

Out of curiosity do you have any additional context or examples of where this helps in the wild?

I have an image organizer app, and it allows copying images to the clipboard.
However, if a very large image gets copied, it gets a Maximum request length exceeded error, which kills the worker thread.

With this patch, it won't kill the worker thread, so the user can keep copying other images (and strings, etc.).

@crumblingstatue
Copy link
Contributor Author

it seems like most of the enum variants are fatal? I'm not an X11 expert but my reading is that anything prefixed with XCB_CONN_ means future requests won't work again because the server has closed our socket. Does that match up with your understanding?

Well, x11rb is its own thing, not bindings to XCB, so I wouldn't take the XCB documentation as "upstream".

@complexspaces
Copy link
Member

However, if a very large image gets copied, it gets a Maximum request length exceeded error, which kills the worker thread.

With this patch, it won't kill the worker thread, so the user can keep copying other images (and strings, etc.).

Thanks, that's helpful to know!

Well, x11rb is its own thing, not bindings to XCB, so I wouldn't take the XCB documentation as "upstream".

That's a very valid point. It was unclear how much of the error handling x11rb inherited from XCB but given that you've tested this patch doesn't result in a dead connection (which would have been XCB_CONN_CLOSED_REQ_LEN_EXCEED if this was XCB), I'm inclined to agree. Given that I had no other feedback, I think this is good to go.

Copy link
Member

@complexspaces complexspaces left a comment

Choose a reason for hiding this comment

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

Thanks again!

Before I merge this, do you mind confirming that you did actually test that future copy operations work after the length exceeded error is logged? After that we're good. I couldn't exactly tell if you had live tested it or were just describing how it would behave.

@crumblingstatue
Copy link
Contributor Author

do you mind confirming that you did actually test that future copy operations work after the length exceeded error is logged?

Yes, I tested it, and can confirm future copies work

@crumblingstatue
Copy link
Contributor Author

If there is a way to check that the connection is closed, we could add a check for that in the event loop, and terminate if the connection is closed.
I'll investigate when I get home.

@complexspaces complexspaces added enhancement New feature or request O-UNIX Work related to X11 or Wayland on UNIX platforms waiting on author Further information is requested labels Jun 18, 2025
@complexspaces
Copy link
Member

Hey again, did you manage to find anything here? I skimmed through x11rb's documentation but didn't spot anything. I'm hoping to cut an arboard release this week with the bug fix backlog.

I'm thinking this might be low-risk to merge and see. I can always make a patch release if this causes unexpected problems.

@crumblingstatue
Copy link
Contributor Author

Sorry, I didn't manage to find anything, and kind of forgot about this.
If you think it's good to merge, go ahead! Thank you!

@complexspaces complexspaces merged commit 5f80bc1 into 1Password:master Jun 24, 2025
11 checks passed
@complexspaces
Copy link
Member

This behavior change is now present in 3.6.0 of arboard on crates.io.

kernelkind pushed a commit to kernelkind/arboard that referenced this pull request Nov 2, 2025
…ls (1Password#186)

* linux/x11: Don't stop worker thread if handling selection request fails

Just because one request fails, that doesn't mean we can't handle
subsequent requests.
Stopping the worker thread on failure means that every subsequent
request will fail, which is usually undesirable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request O-UNIX Work related to X11 or Wayland on UNIX platforms waiting on author Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants