libpq_ssl_clear_error.diff

text/x-patch

Filename: libpq_ssl_clear_error.diff
Type: text/x-patch
Part: 0
Message: Failing SSL connection due to weird interaction with openssl

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/interfaces/libpq/fe-secure.c 7 0
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index b1ad776..2a09c5c 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -323,6 +323,8 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
 
 		/* SSL_read can write to the socket, so we need to disable SIGPIPE */
 		DISABLE_SIGPIPE(conn, spinfo, return -1);
+		/* There could be errors left on OpenSSL's error queue from the application */
+		ERR_clear_error();
 
 rloop:
 		SOCK_ERRNO_SET(0);
@@ -485,6 +487,8 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
 		int			err;
 
 		DISABLE_SIGPIPE(conn, spinfo, return -1);
+		/* There could be errors left on OpenSSL's error queue from the application */
+		ERR_clear_error();
 
 		SOCK_ERRNO_SET(0);
 		n = SSL_write(conn->ssl, ptr, len);
@@ -1375,6 +1379,9 @@ open_client_SSL(PGconn *conn)
 {
 	int			r;
 
+	/* There could be errors left on OpenSSL's error queue from the application */
+	ERR_clear_error();
+
 	r = SSL_connect(conn->ssl);
 	if (r <= 0)
 	{