mirror of
				https://github.com/XRPLF/clio.git
				synced 2025-11-04 11:55:51 +00:00 
			
		
		
		
	fix: Fix writing into dead variables in BlockingCache (#2333)
This commit is contained in:
		@@ -197,22 +197,31 @@ private:
 | 
			
		||||
    std::expected<ValueType, ErrorType>
 | 
			
		||||
    wait(boost::asio::yield_context yield, Updater updater, Verifier verifier)
 | 
			
		||||
    {
 | 
			
		||||
        boost::asio::steady_timer timer{yield.get_executor(), boost::asio::steady_timer::duration::max()};
 | 
			
		||||
        struct SharedContext {
 | 
			
		||||
            SharedContext(boost::asio::yield_context y)
 | 
			
		||||
                : timer(y.get_executor(), boost::asio::steady_timer::duration::max())
 | 
			
		||||
            {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            boost::asio::steady_timer timer;
 | 
			
		||||
            std::optional<std::expected<ValueType, ErrorType>> result;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        auto sharedContext = std::make_shared<SharedContext>(yield);
 | 
			
		||||
        boost::system::error_code errorCode;
 | 
			
		||||
 | 
			
		||||
        std::optional<std::expected<ValueType, ErrorType>> result;
 | 
			
		||||
        boost::signals2::scoped_connection const slot =
 | 
			
		||||
            updateFinished_.connect([yield, &timer, &result](std::expected<ValueType, ErrorType> value) {
 | 
			
		||||
                boost::asio::spawn(yield, [&timer, &result, value = std::move(value)](auto&&) {
 | 
			
		||||
                    result = std::move(value);
 | 
			
		||||
                    timer.cancel();
 | 
			
		||||
            updateFinished_.connect([yield, sharedContext](std::expected<ValueType, ErrorType> value) {
 | 
			
		||||
                boost::asio::spawn(yield, [sharedContext = std::move(sharedContext), value = std::move(value)](auto&&) {
 | 
			
		||||
                    sharedContext->result = std::move(value);
 | 
			
		||||
                    sharedContext->timer.cancel();
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
        if (state_ == State::Updating) {
 | 
			
		||||
            timer.async_wait(yield[errorCode]);
 | 
			
		||||
            ASSERT(result.has_value(), "There should be some value after waiting");
 | 
			
		||||
            return std::move(result).value();
 | 
			
		||||
            sharedContext->timer.async_wait(yield[errorCode]);
 | 
			
		||||
            ASSERT(sharedContext->result.has_value(), "There should be some value after waiting");
 | 
			
		||||
            return std::move(sharedContext->result).value();
 | 
			
		||||
        }
 | 
			
		||||
        return asyncGet(yield, std::move(updater), std::move(verifier));
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user