Robert Haas <robertmh...@gmail.com> writes: > Color me confused; I may need to backpedal rapidly here. I had > thought that what Tom was complaining about was the fact that the > signal handler was taking LWLocks, which I would have thought to be > totally unsafe.
Well, it's unsafe if the signal could interrupt mainline code that is trying to take an LWLock or already holds the same LWLock --- or, if you consider deadlock risks against other processes, already holding other LWLocks might be problematic too. And trying to use facilities like elog or palloc is also pretty unsafe if the mainline is too. The reason the deadlock checker is okay is that there is only a *very* narrow range of mainline code that it could possibly be interrupting, basically nothing but the PGSemaphoreLock() call in ProcSleep. (There's a lot of other code inside the loop there, but notice that it's protected by tests that ensure that it won't run unless the deadlock checker already did.) One salient thing about ProcSleep is that you shouldn't call it while holding any LWLocks, and another is that if you're sleeping while holding regular heavyweight locks, the deadlock checker is exactly what will get you out of trouble if there's a deadlock. Now the HS case likewise appears to be set up so that the signal can only directly interrupt ProcWaitForSignal, so I think the core issue is whether any deadlock situations are possible. Given that this gets called from a low-level place like LockBufferForCleanup, I don't feel too comfortable about that. I certainly haven't seen any analysis or documentation of what locks can safely be held at that point. The deadlock checker only tries to take the LockMgr LWLocks, so extrapolating from whether it is safe to whether touching the ProcArrayLock is safe seems entirely unfounded. It might be worth pointing out here that LockBufferForCleanup is already known to be a risk factor for undetected deadlocks, even without HS in the picture, because of the possibility of deadlocks involving a chain of both heavyweight locks and LWLocks. Whether HS makes it materially worse may be something that we need field experience to determine. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers