summaryrefslogtreecommitdiff
path: root/src/backend/tcop/backend_startup.c
diff options
context:
space:
mode:
authorHeikki Linnakangas2024-07-26 12:12:21 +0000
committerHeikki Linnakangas2024-07-26 12:12:21 +0000
commit20e0e7da9bc0089433c70b2b53ddf6a340ab5df3 (patch)
treea4078e7e981efe7776d4681bfa831fb61c121f47 /src/backend/tcop/backend_startup.c
parentb9e5249c29354186576d8fc00609fe7eaf7c8d25 (diff)
Add test for early backend startup errors
The new test tests the libpq fallback behavior on an early error, which was fixed in the previous commit. This adds an IS_INJECTION_POINT_ATTACHED() macro, to allow writing injected test code alongside the normal source code. In principle, the new test could've been implemented by an extra test module with a callback that sets the FrontendProtocol global variable, but I think it's more clear to have the test code right where the injection point is, because it has pretty intimate knowledge of the surrounding context it runs in. Reviewed-by: Michael Paquier Discussion: https://www.postgresql.org/message-id/CAOYmi%2Bnwvu21mJ4DYKUa98HdfM_KZJi7B1MhyXtnsyOO-PB6Ww%40mail.gmail.com
Diffstat (limited to 'src/backend/tcop/backend_startup.c')
-rw-r--r--src/backend/tcop/backend_startup.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/tcop/backend_startup.c b/src/backend/tcop/backend_startup.c
index a2f94b10504..b840d95e4d1 100644
--- a/src/backend/tcop/backend_startup.c
+++ b/src/backend/tcop/backend_startup.c
@@ -33,6 +33,7 @@
#include "tcop/backend_startup.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
+#include "utils/injection_point.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/timeout.h"
@@ -213,6 +214,21 @@ BackendInitialize(ClientSocket *client_sock, CAC_state cac)
remote_host)));
}
+ /* For testing client error handling */
+#ifdef USE_INJECTION_POINTS
+ INJECTION_POINT("backend-initialize");
+ if (IS_INJECTION_POINT_ATTACHED("backend-initialize-v2-error"))
+ {
+ /*
+ * This simulates an early error from a pre-v14 server, which used the
+ * version 2 protocol for any errors that occurred before processing
+ * the startup packet.
+ */
+ FrontendProtocol = PG_PROTOCOL(2, 0);
+ elog(FATAL, "protocol version 2 error triggered");
+ }
+#endif
+
/*
* If we did a reverse lookup to name, we might as well save the results
* rather than possibly repeating the lookup during authentication.