Bug 403212

Summary: trylock test hangs on FreeBSD
Product: [Developer tools] valgrind Reporter: Mark Johnston <markj>
Component: drdAssignee: Paul Floyd <pjfloyd>
Status: RESOLVED FIXED    
Severity: normal CC: bart.vanassche+kde, emaste, pjfloyd
Priority: NOR    
Version: 3.13.0   
Target Milestone: ---   
Platform: Other   
OS: FreeBSD   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Mark Johnston 2019-01-14 19:22:18 UTC
SUMMARY
The test code in drd/tests/trylock.c attempts to write-lock a POSIX rwlock twice.  The code expects the second attempt to return an error, but POSIX doesn't require that behaviour, and FreeBSD's implementation deadlocks instead.

Seems to me that for the purpose of the test the second wrlock could become a trywrlock; I verified that in this case, drd on FreeBSD detects the attempted recursion and spits out the error message expected by the test.  I can submit a patch if there are no objections to this approach.

STEPS TO REPRODUCE
1. run drd/tests/trylock on FreeBSD

OBSERVED RESULT
trylock hangs and requires a ctrl-C.

EXPECTED RESULT
The test program should complete.
Comment 1 Bart Van Assche 2019-01-15 02:26:55 UTC
This proposal sounds good to me.
Comment 2 Paul Floyd 2020-04-12 16:34:11 UTC
I've dealt with this in my git repo by putting the double call to wrlock in a conditional compilation block.

https://github.com/paulfloyd/freebsd_valgrind/commit/abf44418d52416a625445c782f79717d7b06cadd
Comment 3 Bart Van Assche 2020-04-12 23:52:22 UTC
A candidate fix has been checked in as commit 20dc7278512c ("drd/tests/trylock, FreeBSD: Fix a hang"). I'm not familiar enough with FreeBSD to review the changes in FreeBSD-specific code.