Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzRzb-00050m-ND for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Oct 2017 18:32:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dzRzb-0005zL-9n for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Oct 2017 18:32:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dzRza-0005xv-2d for pgsql-hackers@postgresql.org; Tue, 03 Oct 2017 18:32:30 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dzRzV-00054l-VH for pgsql-hackers@postgresql.org; Tue, 03 Oct 2017 18:32:29 +0000 Received: by mail-wm0-x22e.google.com with SMTP id t69so18450539wmt.2 for ; Tue, 03 Oct 2017 11:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=+rEzhOoEefjFUzv8yLnFpR6OadjKDLf3V1bs6HdxKzk=; b=QZly8xdMdeLUFccLrFP7cTzgXRAKbw2VUYAsZ4RTsp9GoYQfDZ2Ck5hNV+OXZYNfih Mvw7Dvq5jhDRjptn4VG82ubuhEnxyGKyHHGIOhyK5Y2lMy8FXZlwADSBTOnQ7f8PvjD+ TyxddxuoKo8OzsNRM61ishVZy+bdV4SSKBqGkVN4D1qfwx9Qf5JymtPimmvET9LdIZL6 JHTORwgcH6sujZexaKW4FXK7Cg/fr9IXRTa0Tr0sVXyo8Wjn9KsltCHmCr5x4PCRfwk6 XayKYnOoexBkI/Lh/rQcNMQNlsHb3PEE1mlzY3tM10I4yz1aY/KkFWB3vhMrZkXrh6EC EbHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+rEzhOoEefjFUzv8yLnFpR6OadjKDLf3V1bs6HdxKzk=; b=GsbT/mn5Nx0uWsoOMFPLNnQPIW9TIgGqIY+sOmRasysScKXDFxdLXsGN7+1ZsFUdlm 9juik923Ju8Qf7aW9HdcwblDt0VUOrnL6RTdgV753LPAtpXgj9D+EdFwwCMNjh/B1Ztf rF+16njowMuNJnFAEcguEXDZcwnv/YXt0xDEffw7wLuYgR6B484yfHgxkg8cxuswM9qs nIe7IS/fCc33qayjdVhrDp6BtoKYeWqpAvHOgCxlCLQxvRq4t7fXax1v6zvKu7uGxm3m zn1zMApjuvCN2QH/DS+Fa93Mo6z1ovWlr68z44iIswzsVGao2Sj5NxvKqK3nS8gAs8Pe W8dA== X-Gm-Message-State: AHPjjUjHyx9LXPKmEHr3i5bMEDBXb1HasZZZVkYeKL2U4JgnKDiZMFt+ YxnfFDaGqZA7utnj5g6ub+RfZw== X-Google-Smtp-Source: AOwi7QDioaxa8R06j1vQU7rmdoVI6HzYYcwtq/M7cjtpcT5Dq2jVyH1OsIX8Q+6oIIDh0JWYcfc7FQ== X-Received: by 10.28.168.69 with SMTP id r66mr13823298wme.2.1507055544108; Tue, 03 Oct 2017 11:32:24 -0700 (PDT) Received: from [192.168.0.105] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id w18sm10988395wra.61.2017.10.03.11.32.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Oct 2017 11:32:23 -0700 (PDT) Subject: Re: [sqlsmith] stuck spinlock in pg_stat_get_wal_receiver after OOM To: Tom Lane , Alvaro Herrera Cc: Andres Freund , Andreas Seltenreich , pgsql-hackers@postgresql.org, Michael Paquier , Peter Eisentraut , Petr Jelinek References: <20171003145023.nc2ffduj3qvy4b5b@alvherre.pgsql> <22735.1507048202@sss.pgh.pa.us> <6526.1507049903@sss.pgh.pa.us> <23454.1507052652@sss.pgh.pa.us> From: Petr Jelinek Message-ID: <4689c67f-5ffb-7359-a3e9-4abf3908e603@2ndquadrant.com> Date: Tue, 3 Oct 2017 20:32:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <23454.1507052652@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 03/10/17 19:44, Tom Lane wrote: > I wrote: >>> So that's trouble waiting to happen, for sure. At the very least we >>> need to do a single fetch of WalRcv->latch, not two. I wonder whether >>> even that is sufficient, though: this coding requires an atomic fetch of >>> a pointer, which is something we generally don't assume to be safe. > > BTW, I had supposed that this bug was of long standing, but actually it's > new in v10, dating to 597a87ccc9a6fa8af7f3cf280b1e24e41807d555. Before > that walreceiver start/stop just changed the owner of a long-lived shared > latch, and there was no question of stale pointers. > > I considered reverting that decision, but the reason for it seems to have > been to let libpqwalreceiver.c manipulate MyProc->procLatch rather than > having to know about a custom latch. That's probably a sufficient reason > to justify some squishiness in the wakeup logic. Still, we might want to > revisit it if we find any other problems here. That's correct, and because the other users of that library don't have special latch it seemed feasible to standardize on the procLatch. If we indeed wanted to change the decision about this I think we can simply give latch as a parameter to libpqrcv_connect and store it in the WalReceiverConn struct. The connection does not need to live past the latch (although it currently does, but that's just a matter of reordering the code in WalRcvDie() a little AFAICS). -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers