-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
subprocess: Protect proc->ret with a semaphore #4545
Conversation
@@ -41,6 +41,7 @@ struct rz_subprocess_t { | |||
HANDLE stderr_read; | |||
HANDLE proc; | |||
int ret; | |||
RzThreadSemaphore *ret_sem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure this is the correct way. I would expect this to be not thread safe and have a semaphore/lock where this is tossed into a threaded code.
Also this change should be done in rz_sys_fork etc.. Where we use a mutex but it should be a semaphore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this to be not thread safe and have a semaphore/lock where this is tossed into a threaded code.
With d2ad89d, there is a semaphore whether or not the calling code is multithreaded.
Also this change should be done in rz_sys_fork etc.. Where we use a mutex but it should be a semaphore
The mutex in rz_sys_fork seems to be for a purpose unrelated to the data race in the description. There might be a race there too though.
…ss_start()" This reverts commit 96bc5f8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from me, but please wait for @wargio first, since he is more familiar with this code.
298605f
to
98f728c
Compare
Doesn't seem to help the assembly test on macOS:
|
Just noticed this Line 810 in a3ffd6e
Lines 1328 to 1331 in a3ffd6e
so there does appear to be read/write synchronization on |
librz/util/thread_sem.c
Outdated
do { | ||
ret = sem_wait(sem->sem); | ||
} while (ret == -1 && errno == EINTR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe do while(sem_wait(sem->sem) < 0 && errno == EINTR);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok 5b7f8ee
7673f14
to
5b7f8ee
Compare
|
This reverts commit 85089d0.
I think that's it for now ... 85089d0 is inelegant but the CI failure of 7b8ed9e suggests that there's something wrong with the original way of doing things (i think). Even if this pr doesn't fix the macos asm test problem, it does have 2 things going for it:
|
i strongly think the main issue is how we fork and execute. the whole thing in |
i did consider whether pipes were being closed a bit too soon, but that's a quest for another day i suppose |
Your checklist for this pull request
Detailed description
This pr fixes the following
proc->ret
data race, as mentioned on Mattermost:(The above was obtained using gcc TSan on Ubuntu 22.04 -- this build is broken regarding subprocesses in places not related to this pr, such as in
!
)Hopefully, this fixes the problem with macos asm tests as well.
Test plan
All builds are green.
Closing issues
...