diff --git a/mysql-test/suite/encryption/r/innodb-encryption-alter.result b/mysql-test/suite/encryption/r/innodb-encryption-alter.result
index 1d5b88b..075be07 100644
--- a/mysql-test/suite/encryption/r/innodb-encryption-alter.result
+++ b/mysql-test/suite/encryption/r/innodb-encryption-alter.result
@@ -85,3 +85,22 @@ Level	Code	Message
 Warning	140	InnoDB: innodb_encrypt_tables=OFF only allows ENCRYPTION_KEY_ID=1
 Error	1005	Can't create table `test`.`t3` (errno: 140 "Wrong create options")
 Warning	1030	Got error 140 "Wrong create options" from storage engine InnoDB
+create table t1(f1 int not null, f2 int not null)engine=innodb encrypted=yes;
+insert into t1 values(1, 2), (2, 3), (4, 5), (5, 6), (7, 8);
+insert into t1 select * from t1;
+SET DEBUG_DBUG='+d,ib_ddl_crash_before_rename';
+alter table t1 force, algorithm=inplace;
+ERROR HY000: Lost connection to MySQL server during query
+select * from t1;
+f1	f2
+1	2
+2	3
+4	5
+5	6
+7	8
+1	2
+2	3
+4	5
+5	6
+7	8
+drop table t1;
diff --git a/mysql-test/suite/encryption/t/innodb-encryption-alter.test b/mysql-test/suite/encryption/t/innodb-encryption-alter.test
index e8391d9..d988358 100644
--- a/mysql-test/suite/encryption/t/innodb-encryption-alter.test
+++ b/mysql-test/suite/encryption/t/innodb-encryption-alter.test
@@ -105,6 +105,29 @@ DROP TABLE t2;
 CREATE TABLE t3 (a int not null primary key) engine=innodb ENCRYPTION_KEY_ID=4;
 SHOW WARNINGS;
 
+--source include/restart_mysqld.inc
+--let datadir= `select @@datadir`
+--let $_server_id= `SELECT @@server_id`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect
+
+create table t1(f1 int not null, f2 int not null)engine=innodb encrypted=yes;
+insert into t1 values(1, 2), (2, 3), (4, 5), (5, 6), (7, 8);
+insert into t1 select * from t1;
+SET DEBUG_DBUG='+d,ib_ddl_crash_before_rename';
+
+# Write file to make mysql-test-run.pl expect crash
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+--error 2013
+alter table t1 force, algorithm=inplace;
+
+--source include/start_mysqld.inc
+select * from t1;
+drop table t1;
+
+# Work around missing crash recovery at the SQL layer.
+--remove_files_wildcard $datadir/test #sql-*.frm
+
 # reset system
 --disable_query_log
 EVAL SET GLOBAL innodb_encrypt_tables = $encrypt_tables;
diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc
index da40ddd..6a36cc6 100644
--- a/storage/innobase/fil/fil0crypt.cc
+++ b/storage/innobase/fil/fil0crypt.cc
@@ -2374,6 +2374,11 @@ fil_space_crypt_close_tablespace(
 		return;
 	}
 
+	/* If there is no crypt threads then return */
+	if (srv_n_fil_crypt_threads == 0) {
+		return;
+	}
+
 	mutex_enter(&fil_crypt_threads_mutex);
 
 	time_t start = time(0);
