diff --git a/storage/innobase/sync/sync0arr.c b/storage/innobase/sync/sync0arr.c
index b7e8206b575584877e4142fecbf21615f916141d..ce9d42c49218aa98d37282e5a7c6d23780a284f4 100644
--- a/storage/innobase/sync/sync0arr.c
+++ b/storage/innobase/sync/sync0arr.c
@@ -923,12 +923,25 @@ sync_array_print_long_waits(void)
 	ulint		fatal_timeout = srv_fatal_semaphore_wait_threshold;
 	ibool		fatal = FALSE;
 
+#ifdef UNIV_DEBUG_VALGRIND
+	/* Increase the timeouts if running under valgrind because it executes
+	extremely slowly. UNIV_DEBUG_VALGRIND does not necessary mean that
+	we are running under valgrind but we have no better way to tell.
+	See Bug#58432 innodb.innodb_bug56143 fails under valgrind
+	for an example */
+# define SYNC_ARRAY_TIMEOUT	2400
+	fatal_timeout *= 10;
+#else
+# define SYNC_ARRAY_TIMEOUT	240
+#endif
+
 	for (i = 0; i < sync_primary_wait_array->n_cells; i++) {
 
 		cell = sync_array_get_nth_cell(sync_primary_wait_array, i);
 
 		if (cell->wait_object != NULL && cell->waiting
-		    && difftime(time(NULL), cell->reservation_time) > 240) {
+		    && difftime(time(NULL), cell->reservation_time)
+		    > SYNC_ARRAY_TIMEOUT) {
 			fputs("InnoDB: Warning: a long semaphore wait:\n",
 			      stderr);
 			sync_array_cell_print(stderr, cell);
@@ -970,6 +983,8 @@ sync_array_print_long_waits(void)
 			" to the standard error stream\n");
 	}
 
+#undef SYNC_ARRAY_TIMEOUT
+
 	return(fatal);
 }