On Tue, Jan 21, 2020 at 11:22 AM Amit Kapila <amit.kapil...@gmail.com> wrote:
>
> On Fri, Dec 6, 2019 at 11:24 AM vignesh C <vignes...@gmail.com> wrote:
> >
> > It is noticed that in all the 4 cases the message "FATAL:  terminating 
> > connection due to administrator command" does not appear in windows.
> >
> > However the following message is present in the server log file:
> > FATAL:  terminating connection due to administrator command
> >
> > The reason for this looks like:
> > When the server closes a connection, it sends the ErrorResponse packet, and 
> > then closes the socket and terminates the backend process. If the packet is 
> > received before the server closes the connection, the error message is 
> > received in both windows and linux. If the packet is not received before 
> > the server closes the connection, the error message is not received in case 
> > of windows where as in linux it is received.
> >
> > There have been a couple of discussion earlier also on this [1] & [2], but 
> > we could not find any alternate solution.
> >
> > One of the options that msdn suggests in [3] is to use SO_LINGER option, we 
> > had tried this option with no luck in solving. One other thing that we had 
> > tried was to sleep for 1 second before closing the socket, this solution 
> > works if the client is active, whereas in case of inactive clients it does 
> > not solves the problem. One other thought that we had was to simultaneously 
> > check the connection from psql, when we are waiting for query input in 
> > gets_interactive function or have a separate thread to check the connection 
> > status periodically, this might work only in case of psql but will not work 
> > for application which uses libpq. Amit had also suggested one solution in 
> > [4], where he proposed 'I have also tried calling closesocket() explicitly 
> > in our function socket_close which has changed the error message to "could 
> > not receive data from server: Software caused connection abort 
> > (0x00002745/10053)".'
> >
>
> Based on previous investigation and information in this email, I don't
> see anything we can do about this.
>
> > Should we add some documentation for the above behavior.
> >
>
> That sounds reasonable to me.  Any proposal for the same?   One idea
> could be to add something like "Client Disconnection Problems" after
> the "Client Connection Problems" section in docs [1].
>

Thanks for your review and suggestion. I have made a patch based on
similar lines. Attached patch has the doc update with the explanation.
Thoughts?

Regards,
Vignesh
EnterpriseDB: http://www.enterprisedb.com
From e8fc0f70c4bb0bdcff8edc748ae7e04a0fcbf7b4 Mon Sep 17 00:00:00 2001
From: vignesh <vignesh@localhost.localdomain>
Date: Wed, 29 Jan 2020 16:23:51 +0530
Subject: [PATCH] Doc update for the server message not being displayed when
 the client connection is closed by the server.

Doc update for the server message not being displayed when the client
connection is closed by the server in case of
idle_in_transaction_session_timeout, pg_terminate_backend, pg_ctl kill TERM
and drop database with (force). When the server closes client connection, it
sends the ErrorResponse packet, and then closes the socket and terminates the
backend process. If the packet is received before the server closes the
connection, the error message is received in both windows and linux. If the
packet is not received before the server closes the connection, the error
message is not received in case of windows where as in non-windows it is
received.
---
 doc/src/sgml/runtime.sgml | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
index a34d31d..3a0abd7 100644
--- a/doc/src/sgml/runtime.sgml
+++ b/doc/src/sgml/runtime.sgml
@@ -627,6 +627,36 @@ psql: could not connect to server: No such file or directory
      indicate more fundamental problems, like lack of network
      connectivity.
     </para>
+
+    <para>
+     You will get server closed the connection unexpectedly message while
+     trying to execute sql command on disconnected connection. The message is
+     slightly different in windows and non-windows. In non-windows, you will
+     see a FATAL message before the error message:
+<screen>
+FATAL:  terminating connection due to idle-in-transaction timeout
+server closed the connection unexpectedly
+        This probably means the server terminated abnormally
+        before or while processing the request.
+The connection to the server was lost. Attempting reset: Succeeded.
+</screen>
+     In windows, you might not see the FATAL message:
+<screen>
+server closed the connection unexpectedly
+        This probably means the server terminated abnormally
+        before or while processing the request.
+The connection to the server was lost. Attempting reset: Succeeded.
+</screen>
+     This message "FATAL:  terminating connection due to idle-in-transaction
+     timeout" that is sent from server will not be displayed in windows,
+     however it will be present in the log file. The reason for this is, in
+     windows the client cannot receive the message sent by the server when the
+     server has closed the client connection. This behavior can be noticed when
+     the client connection has been disconnected because of
+     idle_in_transaction_session_timeout, pg_terminate_backend, pg_ctl kill
+     TERM and drop database with (force).
+    </para>
+
    </sect2>
   </sect1>
 
-- 
1.8.3.1

Reply via email to