-
Notifications
You must be signed in to change notification settings - Fork 377
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
Protect against real time skips #412
base: master
Are you sure you want to change the base?
Conversation
It isn't used anywhere and therefore I have no way or need to test subsequent changes in it. Signed-off-by: Maciej Wolny <[email protected]>
PR looks good overall. also note that posix-semaphore c++ code is not used under linux, that is why CI passes even though the code itself should not build. |
the asserts against clocktime return value seem dangerous to me. |
Ah, yes - I was planning to do something about this, and then forgot. The only ways |
Are you talking about http://sourceware-org.1504.n7.nabble.com/PATCH-Semaphores-add-sem-timedwait-monotonic-GNU-extension-BZ-14717-td550206.html#a550467 ?
Are you sure? On my Ubuntu 16.04 LTS:
EDIT: Oh, sorry, that was 1.9.9.5 - you're right EDIT: So what's used instead now? |
POSIX functions with names ending with _timedwait use the real time clock and as such are sensitive to changes in system time during the call. This is described in: [1]. This patch implements a wrapper for sem_timedwait() that, if the function call fails, will check if the failure is due to a time warp, and if so, will restart the call. Based on idea and implementation by Ben Hutchings <[email protected]> [1] https://sourceware.org/ml/libc-alpha/2018-12/msg00512.html v2: Check if CLOCK_MONOTONIC is available. Signed-off-by: Maciej Wolny <[email protected]>
POSIX functions with names ending with _timedwait use the real time clock and as such as sensitive to changes in system time during the call. This is described in: [1]. This patch implements a wrapper for pthread_cond_timedwait() that, if the function call fails, will check if the failure is due to a time warp and if so, will restart the call. Based on idea and implementation by Ben Hutchings <[email protected]> [1] https://sourceware.org/ml/libc-alpha/2018-12/msg00512.html v2: Check if CLOCK_MONOTONIC is available. Signed-off-by: Maciej Wolny <[email protected]>
38fa28c
to
8a88b2a
Compare
Ok, I pushed the v2 revision. I think the CI is broken |
I tested this on a fork of 1.9.9.5. I tested legacy paths (i.e CLOCK_MONOTONIC not supported) by changing |
The travis build fails because:
This is something unrelated to this PR. |
Hey I just remembered this. Any chance you could accept it? |
tbh I do not like this approach very much. the issue should be fixed elsewhere, jack is not the only software that has this problem. |
Sorry, I missed the last message @falkTX I think you're right, although glibc folks have already had this discussion and they're not going to fix it, because doing so would supposedely break posix API. They are working on a different API that doesn't have this problem but it's an extension (not in posix) and ultimately it's downstream software that will have to make the switch. Honestly I'm a bit surprised at this counter-intuitive behavior but apparently it's a "feature" not a bug |
POSIX _timedwait API is affected by changes to system time (that is, a sysadmin/service has changed the datetime on the system). This pull request attempts to mitigate that by additionally measuring elapsed time with CLOCK_MONOTONIC, and restarting the _timedwait call if a time skip had occurred.
I've run into this problem in a client's in-vehicle infotainment system. Note there's also an effort to create a GNU extension API that will function in a similar way as _timedwait, but will let the user specify the clock [1]. By choosing CLOCK_MONOTONIC, the user can avoid this issue.
[1] http://sourceware-org.1504.n7.nabble.com/PATCH-Semaphores-add-sem-timedwait-monotonic-GNU-extension-BZ-14717-td550206.html#a550467