diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h
index 9b742d3da7da014d78f4343d285cab45bd9bee38..8e8940373d9afbfde16d9fe349c24a35ee4ad246 100644
--- a/lustre/include/obd_support.h
+++ b/lustre/include/obd_support.h
@@ -58,22 +58,23 @@ extern unsigned int obd_alloc_fail_rate;
 /* Client may skip 1 ping; wait for 2.5 */
 #define PING_EVICT_TIMEOUT (PING_INTERVAL * 5 / 2)
 #define DISK_TIMEOUT 50          /* Beyond this we warn about disk speed */
-#define CONNECTION_SWITCH_MIN 5  /* Connection switching rate limiter */
-#define CONNECTION_SWITCH_MAX 50 /* Max connect interval for nonresponsive
-                                    servers; keep this within the recovery
-                                    period */
+#define CONNECTION_SWITCH_MIN 5U /* Connection switching rate limiter */
+ /* Max connect interval for nonresponsive servers; ~50s to avoid building up
+    connect requests in the LND queues, but within obd_timeout so we don't
+    miss the recovery window */
+#define CONNECTION_SWITCH_MAX min(50U, max(CONNECTION_SWITCH_MIN,obd_timeout))
 #define CONNECTION_SWITCH_INC 5  /* Connection timeout backoff */
 #ifndef CRAY_XT3
 /* In general this should be low to have quick detection of a system 
    running on a backup server. (If it's too low, import_select_connection
    will increase the timeout anyhow.)  */
-#define INITIAL_CONNECT_TIMEOUT max_t(int,CONNECTION_SWITCH_MIN,obd_timeout/20)
+#define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
 #else
 /* ...but for very large systems (e.g. CRAY) we need to keep the initial 
    connect t.o. high (bz 10803), because they will nearly ALWAYS be doing the
    connects for the first time (clients "reboot" after every process, so no
    chance to generate adaptive timeout data. */
-#define INITIAL_CONNECT_TIMEOUT max_t(int,CONNECTION_SWITCH_MIN,obd_timeout/2)
+#define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
 #endif
 #define LONG_UNLINK 300          /* Unlink should happen before now */
 
diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c
index 47fe12dd7e70e1c5ad974008a42b2b91b5b878bc..c584d40c50d8b858c27ee715f294e1af9c3ce3fc 100644
--- a/lustre/ldlm/ldlm_lib.c
+++ b/lustre/ldlm/ldlm_lib.c
@@ -1082,7 +1082,7 @@ void target_cancel_recovery_timer(struct obd_device *obd)
 }
 
 static void reset_recovery_timer(struct obd_device *obd,
-                                 struct ptlrpc_request *req, int first)
+                                 struct ptlrpc_request *req)
 {
         spin_lock_bh(&obd->obd_processing_task_lock);
         if (!obd->obd_recovering) {
@@ -1090,10 +1090,10 @@ static void reset_recovery_timer(struct obd_device *obd,
                 return;
         }
         /* Track the client's largest expected replay time */
-        obd->obd_recovery_timeout = 
-                max((first ? (int)OBD_RECOVERY_TIMEOUT : 
-                     obd->obd_recovery_timeout),
-                    (int)lustre_msg_get_timeout(req->rq_reqmsg));
+        if (lustre_msg_get_timeout(req->rq_reqmsg) > obd->obd_recovery_timeout)
+                obd->obd_recovery_timeout =
+                        lustre_msg_get_timeout(req->rq_reqmsg);
+        LASSERT(obd->obd_recovery_timeout >= OBD_RECOVERY_TIMEOUT);
         cfs_timer_arm(&obd->obd_recovery_timer, 
                       cfs_time_shift(obd->obd_recovery_timeout));
         spin_unlock_bh(&obd->obd_processing_task_lock);
@@ -1118,7 +1118,7 @@ void target_start_recovery_timer(struct obd_device *obd, svc_handler_t handler,
         cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
         spin_unlock_bh(&obd->obd_processing_task_lock);
 
-        reset_recovery_timer(obd, req, 1);
+        reset_recovery_timer(obd, req);
 }
 
 static int check_for_next_transno(struct obd_device *obd)
@@ -1200,7 +1200,7 @@ static void process_recovery_queue(struct obd_device *obd)
                 DEBUG_REQ(D_HA, req, "processing: ");
                 (void)obd->obd_recovery_handler(req);
                 obd->obd_replayed_requests++;
-                reset_recovery_timer(obd, req, 0);
+                reset_recovery_timer(obd, req);
                 /* bug 1580: decide how to properly sync() in recovery */
                 //mds_fsync_super(obd->u.obt.obt_sb);
                 class_export_put(req->rq_export);
diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c
index 0eaddcdcaa97578d045835d30014317290eabd4d..958375ec3c1d64134ef0bdafd30924b33bcb0b6d 100644
--- a/lustre/ptlrpc/client.c
+++ b/lustre/ptlrpc/client.c
@@ -1997,6 +1997,8 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)
                 aa->praa_old_status = lustre_msg_get_status(req->rq_repmsg);
         req->rq_status = 0;
         req->rq_interpret_reply = ptlrpc_replay_interpret;
+        /* Readjust the timeout for current conditions */
+        ptlrpc_at_set_req_timeout(req);
 
         atomic_inc(&req->rq_import->imp_replay_inflight);
         ptlrpc_request_addref(req); /* ptlrpcd needs a ref */
diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c
index 327c2b78e6f5946ddc3bf8da4dc427d6718a5e09..2636df81b45fab6722fb94e8b72a6d205aef785f 100644
--- a/lustre/ptlrpc/import.c
+++ b/lustre/ptlrpc/import.c
@@ -1069,7 +1069,8 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose)
 #ifndef CRAY_XT3
                 /* We want client umounts to happen quickly, no matter the 
                    server state... */
-                req->rq_timeout = min(req->rq_timeout, INITIAL_CONNECT_TIMEOUT);
+                req->rq_timeout = min_t(int, req->rq_timeout,
+                                        INITIAL_CONNECT_TIMEOUT);
 #else
                 /* ... but we always want liblustre clients to nicely 
                    disconnect, so only use the adaptive value. */