Browse Source

fix shutdown stall when freeze + flush

That is related to #2184
Aleksey N. Vinogradov 1 year ago
parent
commit
57c23d9fcf
2 changed files with 13 additions and 8 deletions
  1. 2 1
      src/coroutine.cpp
  2. 11 7
      src/sphinxrt.cpp

+ 2 - 1
src/coroutine.cpp

@@ -967,7 +967,7 @@ bool WaitQueue_c::SuspendAndWaitUntil ( sph::Spinlock_lock& tLock, Worker_c* pAc
 	});
 
 	// resumed. Check if deadline is reached
-	if ( sph::TimeExceeded ( iTimestamp ) )
+	if ( sph::TimeExceeded ( iTimestamp ) || sphInterrupted () )
 	{
 		tLock.lock();
 		// remove from waiting-queue
@@ -976,6 +976,7 @@ bool WaitQueue_c::SuspendAndWaitUntil ( sph::Spinlock_lock& tLock, Worker_c* pAc
 		tLock.unlock();
 		return false;
 	}
+	assert ( !w.is_linked () );
 	return true;
 }
 

+ 11 - 7
src/sphinxrt.cpp

@@ -1194,13 +1194,17 @@ public:
 	// sleep and return false if index's shutdown happened.
 	bool WaitEnabledOrShutdown () const noexcept
 	{
-		return !m_tValue.Wait ( [&] ( const Value_t& tVal ) {
-			if ( tVal.m_bShutdown )
-				return true;
-			if ( tVal.m_eValue != States_e::ENABLED )
-				return false;
-			return tVal.m_iDisabledCounter == 0;
-		}).m_bShutdown;
+		while (true) {
+			auto tVal = m_tValue.WaitForMs ( [&] ( const Value_t& tVal ) {
+				if ( tVal.m_bShutdown )
+					return true;
+				if ( tVal.m_eValue!=States_e::ENABLED )
+					return false;
+				return tVal.m_iDisabledCounter==0;
+			}, 10000 ); // time doesn't matter, as shutdown abandons all timers
+			if ( tVal.m_bShutdown || sphInterrupted() || tVal.m_iDisabledCounter==0 )
+				return !tVal.m_bShutdown;
+		}
 	}
 
 	int GetNumOfLocks() const noexcept