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

Fix #892 #1303

Closed
wants to merge 3 commits into from
Closed

Fix #892 #1303

wants to merge 3 commits into from

Conversation

ilyaluk
Copy link
Contributor

@ilyaluk ilyaluk commented Aug 4, 2017

Removed additional event socket to reduce synchronization problems
and limited workspace update requests count.

Removed additional event socket to reduce synchronisation problems
and limited workspace update requests count.
@@ -24,6 +24,10 @@ char *get_socketpath(void);
*/
int ipc_open_socket(const char *socket_path);
/**
* Issues a single IPC command without reading response.
*/
void ipc_single_command_no_response(int socketfd, uint32_t type, const char *payload, uint32_t *len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need to read the response for further reads to make sense? Also, if chaning the client fixes this then I'm skeptical of the fix, malicious IPC clients shouldn't be able to crash sway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Response is being read by handle_ipc_event.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an advantage to reading it then instead of here? The response is generally meant to be specific to that request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably request rate should be limited on sway side too.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably avoid the deadlock without resorting to rate limiting, no? Is that really the problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright then. Can you add the sway side to this PR?

Copy link
Contributor Author

@ilyaluk ilyaluk Aug 4, 2017

Choose a reason for hiding this comment

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

In i3bar there is one socket and requests made without reading response. Then, one handler handles events and responses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to throttle on sway side. Since all requests processed synchronous, we cannot limit request count (without counting requests in last n seconds), but we could make socket non-blocking, which will help with locks, but on high request rates there may be unexpected problems with data loss.

Copy link
Contributor

Choose a reason for hiding this comment

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

Data loss sounds better than crashing to me.

@ddevault
Copy link
Contributor

ddevault commented Aug 4, 2017

Yeah, this needs to be fixed at the sway level, though I'm not opposed to throttling swaybar too.

This should prevent deadlocks with malicious clients
@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 4, 2017

Looks like after making socket non-blocking scrolling works fine without throttling on swaybar side. But with two sockets it still hangs.

@ddevault
Copy link
Contributor

ddevault commented Aug 4, 2017

I figured that might work. Can you rollback the other changes?

@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 4, 2017

Well, most changes are still needed (it hangs with event socket), but I can rollback throttling.

@ddevault
Copy link
Contributor

ddevault commented Aug 4, 2017

Well, throttling is fine. I'm still not on board with ipc_single_command_no_response.

@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 4, 2017

Okay, I'll try to fix it with two sockets and without _no_response, but I'm not sure if it will work.

@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 5, 2017

I've played a bit with nonblocking sockets on sway side. Data loss could lead to client crashes, for example if ipc response lost. Probably it will be okay with throttling on client side, but nonblocking I/O may cause other unexpected bugs with current implementation.

Generally, the problem is that if client subscribed to some events and not reading them (e.g. swaybar not reading from event socket while processing scroll events), socket buffer fills and then on next write to that socket sway blocks.

Example
Open at least two workspaces and run this script.

@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 5, 2017

Ah, and non-blocking patch is pretty simple. Link

@ddevault
Copy link
Contributor

ddevault commented Aug 5, 2017

Do you also have to deal with E_AGAIN?

@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 6, 2017

Uh huh. I've never worked with async IO before, though.

@ddevault
Copy link
Contributor

ddevault commented Aug 6, 2017

grep for nonblock in the read(3) man page, it's pretty straightforward. Are you going to update this PR?

@ilyaluk
Copy link
Contributor Author

ilyaluk commented Aug 6, 2017

Yeah, I'll figure it out.

No, I'll make another one.

@ilyaluk ilyaluk closed this Aug 6, 2017
@ddevault
Copy link
Contributor

ddevault commented Aug 6, 2017

Sounds good. Many thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants