I wrote:
> ISTM we have to fix RemoveFromWaitQueue to remove the proclock object
> immediately if its count has gone to zero. It should be impossible
> for the lock's count to have gone to zero (that would imply no one
> else holds the lock, so we couldn't be waiting on it) so an Assert
> is sufficient for that part.
I've applied a patch along these lines; it seems to make the problem
go away.
regards, tom lane