Hi Alexandre, v2 looks right to me, the entries are freed now.
An idle worker sleeps in WaitLatch, so it only sees the messages after a catchup signal, that is 2048 queued messages. On a quiet system the stale fds stay, like in the 51 minutes case from the bug report. Nazir's patch covers that case, yours covers the busy worker. Maybe the two threads should be merged, CCing Nazir. LW_SHARED does not work there. SharedInvalBackendInit does pgprocnos[numProcs++] = MyProcNumber, two backends starting at the same time would both hold the shared lock and race on numProcs. Small things: a catchup wakeup is counted in hist_wakeups, the comment rewrites in smgr.c are unrelated, and shmem.h sorts before sinvaladt.h. Thanks, Shihao >
