Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "core: dispatch on exit instead of roundtrip" #114

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

PaideiaDilemma
Copy link
Collaborator

This reverts commit 2c7027d. Without the roundtrip it was possible that session_lock_surface_destroy gets called before unlock_and_destroy is processed.

fixes #107

This reverts commit 2c7027d.
Without the roundtrip it was possible that session_lock_surface_destroy gets called before unlock_and_destroy is processed.
@pdf
Copy link

pdf commented Mar 1, 2024

I've not been able to reproduce the RSOD with this change, and previously could do so within ~10 attempts. Sometimes hyprlock takes a number of seconds to return on exit now, I suspect that when that occurs it would previously have triggerred the RSOD.

@vaxerski
Copy link
Member

vaxerski commented Mar 1, 2024

on the other hand with it some people get freezes.

@pdf
Copy link

pdf commented Mar 1, 2024

For reference this appears to be the related issue: #87

We definitely need to synchronize somehow - hyprlock can never be allowed to destroy the surface before the unlock signal is sent.

I don't know enough about wayland etc to be of much use here, but the docs for ext_session_lock_v1_unlock_and_destroy have this to say:

Note that a correct client that wishes to exit directly after unlocking
the session must use the wl_display.sync request to ensure the server
receives and processes the unlock_and_destroy request. Otherwise
there is no guarantee that the server has unlocked the session due
to the asynchronous nature of the Wayland protocol. For example,
the server might terminate the client with a protocol error before
it processes the unlock_and_destroy request.

The docs for wl_display suggest that "a module that runs using its own proxy queue that needs to do display roundtrip must wrap the wl_display proxy object before sending the wl_display.sync request", which is what wl_display_roundtrip appears to do, but I'm not certain if that requirement applies here.

The docs for wl_display_roundtrip/wl_display_roundtrip_queue do mention that they're not thread-safe and can deadlock under some conditions.

Can we perhaps just call wl_display_sync directly, and use the returned callback to synchronize? I don't write C++ unfortunately.

If that's not an option then I suspect what's required here is to continue calling wl_display_roundtrip, but add a mutex around this and whatever read operations may trigger the deadlock.

@vaxerski
Copy link
Member

vaxerski commented Mar 1, 2024

I guess I'll merge this.

This is called from the main thread so it should be safe

@vaxerski vaxerski merged commit 64bdc47 into hyprwm:main Mar 1, 2024
1 check passed
@pdf
Copy link

pdf commented Mar 1, 2024

I wonder if this might be relevant, from the docs for wl_display_dispatch_queue, which is used internally by wl_display_roundtrip:

In a multi threaded environment, do not manually wait using poll() (or equivalent) before calling this function, 
as doing so might cause a dead lock. If external reliance on poll() (or equivalent) is required, see 
wl_display_prepare_read_queue() of how to do so.

I see that we're polling the display for events in a thread at

int ret = poll(pollfds, 1, 5000 /* 5 seconds, reasonable. It's because we might need to terminate */);

Again though, all of this is quite outside my wheel-house, so maybe this is unrelated and not relevant.

@vaxerski
Copy link
Member

vaxerski commented Mar 1, 2024

idk either tbh lol

@PaideiaDilemma PaideiaDilemma mentioned this pull request Mar 2, 2024
@PaideiaDilemma
Copy link
Collaborator Author

I think this is not really relevant, since the event loop is single threaded. The poll thread might get "stray" poll events but that should not matter.

The freezes come from an unfortunate ordering where the poll thread waits for the eventLoopMutex. Then the main thread sets m_bTerminate and and then the poll thead polls again, which causes a 5 second freeze.

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.

Pressing enter without any password makes the entire screen red.
3 participants