[pve-devel] [PATCH cluster v2 1/3] ipcc_send_rec: retry once if cached connection failed

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Dec 20 13:20:16 CET 2017


A restart of pmxcfs invalidates the connection cache, we only set the
cached connection to NULL for this case and the next call to
ipcc_send_rec would connect newly.

Instead, retry directly one single time in this case.
If this try fails we return undef anyway and for the case where it
succeeds but the request to the pmxcfs server fails for other reason
stop retrying as here it won't change the problem and would probably
end in an endless loop.
---

changes v1 -> v2:
* use local non-static variable to track if we retried, as we need
  this information only on a per-call basis

 data/PVE/IPCC.xs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/data/PVE/IPCC.xs b/data/PVE/IPCC.xs
index ded9472..a0d3612 100644
--- a/data/PVE/IPCC.xs
+++ b/data/PVE/IPCC.xs
@@ -46,6 +46,7 @@ SV * data;
 PROTOTYPE: $;$
 CODE:
 {
+	int retried_connection = 0;
 	pid_t cpid = getpid();
 
 	/* Each process needs its own ipcc connection,
@@ -56,6 +57,7 @@ CODE:
 	}
 
 	if (conn == NULL) {
+retry_connection:
 		qb_log_init("IPCC.xs", LOG_USER, LOG_EMERG);
 		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_TRUE);
 		conn = qb_ipcc_connect(PCS_SOCKET_NAME, MAX_MSG_SIZE);
@@ -89,6 +91,11 @@ CODE:
 	if (res < 0) {
 		qb_ipcc_disconnect(conn);
 		conn = NULL;
+		// the first request after restart will always fail, retry once
+		if (!retried_connection) {
+			retried_connection = 1;
+			goto retry_connection;
+		}
 		errno = -res;
 		XSRETURN_UNDEF;
 	}
-- 
2.11.0





More information about the pve-devel mailing list