After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 794977 - gstpoll: should not handle POLLPRI as read
gstpoll: should not handle POLLPRI as read
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: 1.15.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-04-04 14:37 UTC by Guillaume Desmottes
Modified: 2018-06-08 15:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
poll: stop treating on POLLPRI as 'read' (1.59 KB, patch)
2018-04-12 10:01 UTC, Guillaume Desmottes
none Details | Review
poll: add API to watch for POLLPRI (4.60 KB, patch)
2018-04-12 10:01 UTC, Guillaume Desmottes
none Details | Review
poll: stop treating on POLLPRI as 'read' (1.59 KB, patch)
2018-06-08 07:32 UTC, Guillaume Desmottes
committed Details | Review
poll: add API to watch for POLLPRI (4.63 KB, patch)
2018-06-08 07:32 UTC, Guillaume Desmottes
committed Details | Review

Description Guillaume Desmottes 2018-04-04 14:37:29 UTC
Current implementation of GstPoll considers "can read" as having either POLLIN or POLLPRI being set : https://cgit.freedesktop.org/gstreamer/gstreamer/tree/gst/gstpoll.c#n1023

This may lead to client being awaken because of POLLPRI, starting a blocking read and getting stuck because there is actually nothing to read.
It also prevents applications to wait only on POLLPRI.

I'd suggest to remove this behavior in the read code and add specific API for POLLPRI: gst_poll_fd_has_pri() (or has_priority?) and gst_poll_fd_ctl_pri
Comment 1 Guillaume Desmottes 2018-04-12 10:01:22 UTC
Created attachment 370838 [details] [review]
poll: stop treating on POLLPRI as 'read'

Current code was considering "can read" as having either POLLIN or POLLPRI being
set.
This may lead to client being awaken because of POLLPRI, starting a blocking
read and getting stuck because there is actually nothing to read.

This patch removes POLLPRI handling in read code and I'll add specific
API to wait for POLLPRI.
Comment 2 Guillaume Desmottes 2018-04-12 10:01:27 UTC
Created attachment 370839 [details] [review]
poll: add API to watch for POLLPRI

Windows doesn't seem to have an equivalent of POLLPRI so disabled those
functions on this platform.

This API can be used, for example, to wait for video4linux events which
are using POLLPRI.
Comment 3 Guillaume Desmottes 2018-04-12 10:01:51 UTC
What about something like this?
Comment 4 Tim-Philipp Müller 2018-04-12 11:07:49 UTC
I've got nothing against this in principle, but I'm concerned that it might break backwards compatibility.

Someone doing a read and getting stuck - why can't they just set the socket to non-blocking if they use GstPoll anyway? That sounds like a potential problem in itself?
Comment 5 Guillaume Desmottes 2018-04-12 11:43:08 UTC
Sure that was just an example.

When I discussed that with Nicolas he also mentioned that this could be a problem in v4l2. With current code if we receive an event (POLLPRI) we'll end up doing a blocking and uncancellable DQBUF assuming there are buffers ready.
Comment 6 Nicolas Dufresne (ndufresne) 2018-04-12 12:12:18 UTC
(In reply to Tim-Philipp Müller from comment #4)
> I've got nothing against this in principle, but I'm concerned that it might
> break backwards compatibility.

Unless we want to supports bugs in Linux < 2.4, no. POLLPRI never applies to read(). So polling it will simply wakeup the CPU for no reason if you have a non-blocking FD, and cause blocking IO if you have a blocking FD.

> 
> Someone doing a read and getting stuck - why can't they just set the socket
> to non-blocking if they use GstPoll anyway? That sounds like a potential
> problem in itself?

I think Guillaume meant doing a systemcall, blocking / non-blocking cannot be controlled on all the syscalls. For V4L2 it is possible to control that, but we don't because we support V4L2 driver without polling capabilities. I'm fine dropping this support of course. Yet, I think fixing GstPoll to properly differentiate these two, which have a totally orthogonal meaning. We want from GstPoll to tell us the truth, so we don't randomly call into the OS to "try" and see what the poll() call already said.

A small note about windows, the polling event for "accept" is different on that platform. I think it's fine to manage this as read, because that how it is expected to be on posix, and listener don't have any other data anyway.
Comment 7 Guillaume Desmottes 2018-04-16 13:22:08 UTC
Regardless of the change in the existing poll read code, do we agree about this new specific API for POLLPRI?
I have some custom code using it so would like to move this API forward if possible.
Comment 8 Nicolas Dufresne (ndufresne) 2018-06-07 18:48:32 UTC
Review of attachment 370839 [details] [review]:

I'd like to merge this, pleas add the missing Since marker.
Comment 9 Guillaume Desmottes 2018-06-08 07:32:50 UTC
Created attachment 372600 [details] [review]
poll: stop treating on POLLPRI as 'read'

Current code was considering "can read" as having either POLLIN or POLLPRI being
set.
This may lead to client being awaken because of POLLPRI, starting a blocking
read and getting stuck because there is actually nothing to read.

This patch removes POLLPRI handling in read code and I'll add specific
API to wait for POLLPRI.
Comment 10 Guillaume Desmottes 2018-06-08 07:32:58 UTC
Created attachment 372601 [details] [review]
poll: add API to watch for POLLPRI

Windows doesn't seem to have an equivalent of POLLPRI so disabled those
functions on this platform.

This API can be used, for example, to wait for video4linux events which
are using POLLPRI.
Comment 11 Guillaume Desmottes 2018-06-08 07:33:29 UTC
Marked added and patches rebased.
Comment 12 Nicolas Dufresne (ndufresne) 2018-06-08 15:54:33 UTC
Attachment 372600 [details] pushed as 1e321eb - poll: stop treating on POLLPRI as 'read'
Attachment 372601 [details] pushed as b259313 - poll: add API to watch for POLLPRI