From 5b001957c7e7e4e102f82bebf408712c8e6333c4 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Thu, 30 Jan 2025 16:11:27 +0100
Subject: [PATCH] input/async: skip resume and seek if there is a pending error

The resume/seek was received asynchronously and meanwhile an error
might have occurred that needs to be handled.

This fixes another NFS-related crash bug.
---
 src/input/AsyncInputStream.cxx | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx
index 9a3bd5baf..8a60fcfa0 100644
--- a/src/input/AsyncInputStream.cxx
+++ b/src/input/AsyncInputStream.cxx
@@ -251,6 +251,14 @@ AsyncInputStream::DeferredResume() noexcept
 {
 	const std::scoped_lock protect{mutex};
 
+	if (postponed_exception) {
+		/* do not proceed, first the caller must handle the
+                   pending error */
+		caller_cond.notify_one();
+		InvokeOnAvailable();
+		return;
+	}
+
 	try {
 		Resume();
 	} catch (...) {
@@ -267,6 +275,14 @@ AsyncInputStream::DeferredSeek() noexcept
 	if (seek_state != SeekState::SCHEDULED)
 		return;
 
+	if (postponed_exception) {
+		/* do not proceed, first the caller must handle the
+                   pending error */
+		caller_cond.notify_one();
+		InvokeOnAvailable();
+		return;
+	}
+
 	try {
 		Resume();