Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSk7v-00Fe3j-V6 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jan 2024 20:45:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rSk7u-008J5j-Vk for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jan 2024 20:45:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSk7u-008Iyn-Eo for pgsql-hackers@lists.postgresql.org; Wed, 24 Jan 2024 20:45:38 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rSk7r-003BVl-To for pgsql-hackers@postgresql.org; Wed, 24 Jan 2024 20:45:37 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5ff84214fc7so58523537b3.0 for ; Wed, 24 Jan 2024 12:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1706129135; x=1706733935; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=NOUB9fPQo8KJjDRZJnsWRVWxl21SUaqvunnllBqnN5A=; b=N0EpjJY06GVNAFj95QJDiDifkrKBVHrrRWy0vHTkU2SPJjdWCjX+jFfij8KnOZ2G3y AYOvYRrsxjfyZ+ASQ1pUmFNh2iwsvsjSYQ4q7LlNlYDT/xmwBuhGI5Mwh9dEZ4ci3qrz YaVnq4KMDiFaIHeUcE+/1+zxzWfPqsDYm0RJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706129135; x=1706733935; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NOUB9fPQo8KJjDRZJnsWRVWxl21SUaqvunnllBqnN5A=; b=exnqCFyCJiWNqk1SdJ5U7TxWggZGjze5L1oKAjU7xhX1AzRaXdzI66pGPuraIdhQSm o3pqcavFl1nFknDsPoT+6pJmHUgE1RK+ONfCpuxk100Z1NwyTJ82n29He2EFNoe2wYZ4 eVyps5nfT67d0vb7iBJ3rVg8BF7puE1A2kXmVb3jeHf7K7NEk1Fv0kqeJyxIh62fwLSM g6Hhn4xI5WlA0XYRvdeRwTaNMFXR84Z0e5XTmNosa/LY3kEcFHsOm99K54bTzWWn74JT sTNI59JOPuqTGoSWbgGlHLLERKe4ahKuIiEj6MJ+faQxZsHRwATP7puBQAsFWCv5EE3a YrAw== X-Gm-Message-State: AOJu0YzI7U7pnYUpp4ooVV86EC/TdQEAe7+WHnD1lTVwSf8rF49+vQEd x/xgXN0ipxBemNxlcbe7eQwSiGbF9CTh980o5H5IfILqXo6bE130qwilNf/Qzw== X-Google-Smtp-Source: AGHT+IFC7Wo0RW5//5XKbygvcyYc0P8awUew2KwdHsM9BTweYgXUTxKNJKZNsC8BE0KSHPATQNs+Ew== X-Received: by 2002:a5b:cc3:0:b0:dc2:418f:f756 with SMTP id e3-20020a5b0cc3000000b00dc2418ff756mr1155004ybr.36.1706129135030; Wed, 24 Jan 2024 12:45:35 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id b6-20020a252e46000000b00dc254858399sm2955528ybn.2.2024.01.24.12.45.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2024 12:45:34 -0800 (PST) Date: Wed, 24 Jan 2024 12:45:32 -0800 From: Noah Misch To: Fujii Masao Cc: pgsql-hackers@postgresql.org Subject: Re: dblink query interruptibility Message-ID: <20240124204532.1b.nmisch@google.com> References: <20231122012945.74@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 25, 2024 at 04:23:39AM +0900, Fujii Masao wrote: > I found that this patch was committed at d3c5f37dd5 and changed the > error message in postgres_fdw slightly. Here's an example: > > #1. Begin a new transaction. > #2. Execute a query accessing to a foreign table, like SELECT * FROM > > #3. Terminate the *remote* session corresponding to the foreign table. > #4. Commit the transaction, and then currently the following error > message is output. > > ERROR: FATAL: terminating connection due to administrator command > server closed the connection unexpectedly > This probably means the server terminated abnormally > before or while processing the request. > invalid socket > > Previously, before commit d3c5f37dd5, the error message at #4 did not > include "invalid socket." Now, after the commit, it does. Is this > change intentional? No. It's a consequence of an intentional change in libpq call sequence, but I was unaware I was changing an error message. > + /* Consume whatever data is available from the socket */ > + if (PQconsumeInput(conn) == 0) > + { > + /* trouble; expect PQgetResult() to return NULL */ > + break; > + } > + } > + > + /* Now we can collect and return the next PGresult */ > + return PQgetResult(conn); > > This code appears to cause the change. When the remote session ends, > PQconsumeInput() returns 0 and marks conn->socket as invalid. > Subsequent PQgetResult() calls pqWait(), detecting the invalid socket > and appending "invalid socket" to the error message. > > I think the "invalid socket" message is unsuitable in this scenario, > and PQgetResult() should not be called after PQconsumeInput() returns > 0. Thought? The documentation is absolute about the necessity of PQgetResult(): PQsendQuery cannot be called again (on the same connection) until PQgetResult has returned a null pointer, indicating that the command is done. PQgetResult must be called repeatedly until it returns a null pointer, indicating that the command is done. (If called when no command is active, PQgetResult will just return a null pointer at once.) Similar statements also appear in libpq-pipeline-results, libpq-pipeline-errors, and libpq-copy. So, unless the documentation or my reading of it is wrong there, I think the answer is something other than skipping PQgetResult(). Perhaps PQgetResult() should not append "invalid socket" in this case? The extra line is a net negative, though it's not wrong and not awful. Thanks for reporting the change.