diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc
index 66ca04bbf04..5d2cbe104a0 100644
--- a/storage/innobase/trx/trx0trx.cc
+++ b/storage/innobase/trx/trx0trx.cc
@@ -1380,6 +1380,7 @@ inline void trx_t::commit_in_memory(const mtr_t *mtr)
 
 void trx_t::commit_cleanup()
 {
+  bool trx_read_only;
   mutex.wr_lock();
   dict_operation= false;
 
@@ -1388,11 +1389,12 @@ void trx_t::commit_cleanup()
   mod_tables.clear();
 
   assert_freed();
+  trx_read_only= read_only;
   trx_init(this);
   mutex.wr_unlock();
 
   ut_a(error_state == DB_SUCCESS);
-  if (!srv_read_only_mode)
+  if (!trx_read_only)
     srv_wake_purge_thread_if_not_active();
 }
 
