diff --git a/lustre/llite/statahead.c b/lustre/llite/statahead.c
index 061fcc86b93812375f2ca01175d430c34d29f8e7..69f701e1e182068759442ab175b6fb684f1988c6 100644
--- a/lustre/llite/statahead.c
+++ b/lustre/llite/statahead.c
@@ -1587,6 +1587,9 @@ static int start_statahead_thread(struct inode *dir, struct dentry *dentry)
 			   lli->lli_opendir_pid);
 	thread = &sai->sai_thread;
 	if (IS_ERR(task)) {
+		spin_lock(&lli->lli_sa_lock);
+		lli->lli_sai = NULL;
+		spin_unlock(&lli->lli_sa_lock);
 		rc = PTR_ERR(task);
 		CERROR("can't start ll_sa thread, rc: %d\n", rc);
 		GOTO(out, rc);
@@ -1607,10 +1610,8 @@ out:
 	/* once we start statahead thread failed, disable statahead so that
 	 * subsequent stat won't waste time to try it. */
 	spin_lock(&lli->lli_sa_lock);
-	if (sai != NULL && lli->lli_sai == sai) {
+	if (lli->lli_opendir_pid == current->pid)
 		lli->lli_sa_enabled = 0;
-		lli->lli_sai = NULL;
-	}
 	spin_unlock(&lli->lli_sa_lock);
 
 	if (sai != NULL)