diff --git a/src/slurmctld/controller.c b/src/slurmctld/controller.c
index 866f7efba0cfcc9df4aee70e051ea965fe3c498f..f873c76992ceed35e70df438c65da18bd76bf06b 100644
--- a/src/slurmctld/controller.c
+++ b/src/slurmctld/controller.c
@@ -706,7 +706,7 @@ static void *_slurmctld_background(void *no_data)
 	static time_t last_timelimit_time;
 	static time_t last_assert_primary_time;
 	time_t now;
-	int ping_interval;
+	int i, ping_interval;
 	DEF_TIMERS;
 
 	/* Locks: Read config */
@@ -842,6 +842,14 @@ static void *_slurmctld_background(void *no_data)
 		if (DELTA_TIMER > 1000000)	/* more than one second */ 
 			info("_slurmctld_background loop %s", TIME_STR);
 	}
+
+	for (i=0; i<20; i++) {
+		if (agent_retry(0) == 0)
+			break;
+		usleep(1000);
+	}
+	if (agent_retry(0))
+		error("terminating with %d pending message agent requests", cnt);
 	debug3("_slurmctld_background shutting down");
 
 	return NULL;