xserver icon indicating copy to clipboard operation
xserver copied to clipboard

RFC: os: WaitForSomething(): also try to flush out older buffer content

Open metux opened this issue 6 months ago • 4 comments

Always try to flush out anything we have, even for clients that had been stuck for a short while because we've tried to send out too much at once. If we'd only do it when someting new is in the queue, then those clients might get stuck for long time, until something else triggers the flush by mere accident.

metux avatar Aug 07 '25 15:08 metux

If NewOutputPending is false, do we have anything to flush?

stefan11111 avatar Aug 07 '25 21:08 stefan11111

There shouldn't be anything to flush if NewOutputPending is false. That if the logic has no bugs. Honestly, it looks like that flag was introduced exactly to prevent too frequent useless write attempts.

Not sure how can we get those stuck clients, I don't see any issues with the code. NewOutputPending is set to false only when there no clients with pending writes at all, or there are only clients that can't handle any writes and we're waiting for their sockets to become writable (and when it happens NewOutputPending will be set to true).

algrid avatar Aug 07 '25 23:08 algrid

There shouldn't be anything to flush if NewOutputPending is false.

We do. One of the last flush attempts on some client could have just been a partial write, because socket buffer was full (and client didn't keep up fast enough).

The current implementation, IMHO, only retries when something else has written something new.

Not sure how can we get those stuck clients,

Slow network connection, or just SIGSTOP'ing a client.

I don't see any issues with the code. NewOutputPending is set to false only when there no clients with pending writes at all, or there are only clients that can't handle any writes and we're waiting for their sockets to become writable (and when it happens NewOutputPending will be set to true).

hmm, just seen that ClientReady() is setting NewOutputPending when ospoll signalling a socket can accept more writes, so perhaps my assumption was wrong.

metux avatar Aug 08 '25 11:08 metux

@metux yep, and here is the relevant code where we start waiting for the socket to become writable (when it becomes stuck).

Maybe for now just let your and @stefan11111 recent changes bake a little bit in the master and check if there is an actual problem there? I would hope that it's fine as it is.  

algrid avatar Aug 08 '25 17:08 algrid