mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-19 17:37:45 +02:00
Fix crash during reconnect
This commit is contained in:
parent
e480268097
commit
b566b42ee0
2 changed files with 12 additions and 3 deletions
|
@ -79,10 +79,15 @@ uint16_t PendingRequest::id() const
|
|||
void PendingRequest::startTimer(const chronos::usec& timeout)
|
||||
{
|
||||
timer_.expires_after(timeout);
|
||||
timer_.async_wait([this, self = shared_from_this()](boost::system::error_code ec)
|
||||
timer_.async_wait([this, me = weak_from_this()](boost::system::error_code ec)
|
||||
{
|
||||
auto self = me.lock();
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
if (!handler_)
|
||||
return;
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
// !ec => expired => timeout
|
||||
|
@ -581,6 +586,7 @@ void ClientConnectionWss::disconnect()
|
|||
getWs().next_layer().lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
||||
getWs().next_layer().lowest_layer().close(ec);
|
||||
}
|
||||
|
||||
boost::asio::post(strand_, [this]() { pendingRequests_.clear(); });
|
||||
ssl_ws_ = std::nullopt;
|
||||
LOG(DEBUG, LOG_TAG) << "Disconnected\n";
|
||||
|
|
|
@ -169,6 +169,7 @@ void Controller::getNextMessage()
|
|||
{
|
||||
if (ec)
|
||||
{
|
||||
LOG(ERROR, LOG_TAG) << "Error receiving next message: " << ec << "\n";
|
||||
reconnect();
|
||||
return;
|
||||
}
|
||||
|
@ -425,6 +426,7 @@ void Controller::start()
|
|||
|
||||
void Controller::reconnect()
|
||||
{
|
||||
LOG(INFO, LOG_TAG) << "Reconnecting\n";
|
||||
timer_.cancel();
|
||||
clientConnection_->disconnect();
|
||||
player_.reset();
|
||||
|
@ -467,11 +469,12 @@ void Controller::worker()
|
|||
serverSettings_ = std::move(response);
|
||||
LOG(INFO, LOG_TAG) << "ServerSettings - buffer: " << serverSettings_->getBufferMs() << ", latency: " << serverSettings_->getLatency()
|
||||
<< ", volume: " << serverSettings_->getVolume() << ", muted: " << serverSettings_->isMuted() << "\n";
|
||||
}
|
||||
});
|
||||
|
||||
// Do initial time sync with the server
|
||||
sendTimeSyncMessage(50);
|
||||
}
|
||||
});
|
||||
|
||||
// Start receiver loop
|
||||
getNextMessage();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue