Ensure that bad protocol ERROR message is sent to the frontend
authorPavan Deolasee <[email protected]>
Tue, 31 Jul 2018 06:00:01 +0000 (11:30 +0530)
committerPavan Deolasee <[email protected]>
Tue, 31 Jul 2018 07:07:49 +0000 (12:37 +0530)
In case of receiving bad protocol messages received by the GTM proxy, let
the client know about the error messages.

src/gtm/proxy/proxy_main.c

index 8db81b1e3c8f5888696e88ee647588112c714a5e..ba976eb938bec9b7bdac09b757d2b4b514f799eb 100644 (file)
@@ -1177,6 +1177,9 @@ GTMProxy_ThreadMain(void *argp)
                                 */
                                if (conninfo->con_disconnected)
                                {
+                                       EmitErrorReport(conninfo->con_port);
+                                       if (conninfo->con_port->sock > 0)
+                                               StreamClose(conninfo->con_port->sock);
                                        GTMProxy_ThreadRemoveConnection(thrinfo, conninfo);
                                        pfree(conninfo);
                                        ii--;
@@ -2329,8 +2332,6 @@ GTMProxy_HandshakeConnection(GTMProxy_ConnectionInfo *conninfo)
        if (startup_type != 'A')
        {
                conninfo->con_disconnected = true;
-               if (conninfo->con_port->sock > 0)
-                       StreamClose(conninfo->con_port->sock);
                ereport(ERROR,
                                (EPROTO,
                                 errmsg("Expecting a startup message, but received %c",
@@ -2347,8 +2348,6 @@ GTMProxy_HandshakeConnection(GTMProxy_ConnectionInfo *conninfo)
        if (pq_getmessage(conninfo->con_port, &inBuf, 0))
        {
                conninfo->con_disconnected = true;
-               if (conninfo->con_port->sock > 0)
-                       StreamClose(conninfo->con_port->sock);
                ereport(ERROR,
                                (EPROTO,
                                 errmsg("Expecting PGXC Node ID, but received EOF")));