mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-02 03:37:00 +02:00
fix crash in control server
This commit is contained in:
parent
2939ace883
commit
12a11e12a9
4 changed files with 29 additions and 25 deletions
|
@ -31,11 +31,12 @@ else
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Simplify building debuggable executables 'make DEBUG=-g STRIP=echo'
|
# Simplify building debuggable executables 'make DEBUG=-g STRIP=echo'
|
||||||
DEBUG=-O3
|
DEBUG=-O2
|
||||||
|
SANITIZE=
|
||||||
|
#-fsanitize=thread
|
||||||
|
|
||||||
|
CXXFLAGS += $(ADD_CFLAGS) $(SANITIZE) -std=c++14 -Wall -Wpedantic -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
|
||||||
CXXFLAGS += $(ADD_CFLAGS) -std=c++14 -Wall -Wpedantic -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
|
LDFLAGS = $(ADD_LDFLAGS) $(SANITIZE) -lvorbis -lvorbisenc -logg -lFLAC
|
||||||
LDFLAGS = $(ADD_LDFLAGS) -lvorbis -lvorbisenc -logg -lFLAC
|
|
||||||
OBJ = snapserver.o config.o control_server.o control_session_tcp.o control_session_http.o stream_server.o stream_session.o streamreader/streamUri.o streamreader/base64.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/airplayStream.o streamreader/spotifyStream.o streamreader/watchdog.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/sampleFormat.o
|
OBJ = snapserver.o config.o control_server.o control_session_tcp.o control_session_http.o stream_server.o stream_session.o streamreader/streamUri.o streamreader/base64.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/airplayStream.o streamreader/spotifyStream.o streamreader/watchdog.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/sampleFormat.o
|
||||||
|
|
||||||
ifneq (,$(TARGET))
|
ifneq (,$(TARGET))
|
||||||
|
|
|
@ -47,23 +47,19 @@ ControlServer::~ControlServer()
|
||||||
|
|
||||||
void ControlServer::cleanup()
|
void ControlServer::cleanup()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> mlock(session_mutex_);
|
auto new_end = std::remove_if(sessions_.begin(), sessions_.end(), [](std::weak_ptr<ControlSession> session) { return session.expired(); });
|
||||||
for (auto it = sessions_.begin(); it != sessions_.end();)
|
auto count = distance(new_end, sessions_.end());
|
||||||
|
if (count > 0)
|
||||||
{
|
{
|
||||||
if (it->expired())
|
SLOG(ERROR) << "Removing " << count << " inactive session(s), active sessions: " << sessions_.size() - count << "\n";
|
||||||
{
|
sessions_.erase(new_end, sessions_.end());
|
||||||
SLOG(ERROR) << "Session inactive. Removing\n";
|
|
||||||
sessions_.erase(it++);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ControlServer::send(const std::string& message, const ControlSession* excludeSession)
|
void ControlServer::send(const std::string& message, const ControlSession* excludeSession)
|
||||||
{
|
{
|
||||||
cleanup();
|
std::lock_guard<std::recursive_mutex> mlock(session_mutex_);
|
||||||
for (auto s : sessions_)
|
for (auto s : sessions_)
|
||||||
{
|
{
|
||||||
if (auto session = s.lock())
|
if (auto session = s.lock())
|
||||||
|
@ -72,6 +68,7 @@ void ControlServer::send(const std::string& message, const ControlSession* exclu
|
||||||
session->sendAsync(message);
|
session->sendAsync(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,6 +200,7 @@ void ControlServer::stop()
|
||||||
cancel_accept(acceptor_http_.first.get());
|
cancel_accept(acceptor_http_.first.get());
|
||||||
cancel_accept(acceptor_http_.second.get());
|
cancel_accept(acceptor_http_.second.get());
|
||||||
std::lock_guard<std::recursive_mutex> mlock(session_mutex_);
|
std::lock_guard<std::recursive_mutex> mlock(session_mutex_);
|
||||||
|
cleanup();
|
||||||
for (auto s : sessions_)
|
for (auto s : sessions_)
|
||||||
{
|
{
|
||||||
if (auto session = s.lock())
|
if (auto session = s.lock())
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# default values are commented
|
# default values are commented
|
||||||
# uncomment to change them
|
# uncomment and edit to change them
|
||||||
|
|
||||||
|
|
||||||
# HTTP RPC ####################################################################
|
# HTTP RPC ####################################################################
|
||||||
|
|
|
@ -75,12 +75,15 @@ void StreamSession::stop()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
{
|
||||||
if (ec)
|
std::lock_guard<std::mutex> socketLock(socketMutex_);
|
||||||
LOG(ERROR) << "Error in socket shutdown: " << ec.message() << "\n";
|
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
||||||
socket_.close(ec);
|
if (ec)
|
||||||
if (ec)
|
LOG(ERROR) << "Error in socket shutdown: " << ec.message() << "\n";
|
||||||
LOG(ERROR) << "Error in socket close: " << ec.message() << "\n";
|
socket_.close(ec);
|
||||||
|
if (ec)
|
||||||
|
LOG(ERROR) << "Error in socket close: " << ec.message() << "\n";
|
||||||
|
}
|
||||||
if (readerThread_ && readerThread_->joinable())
|
if (readerThread_ && readerThread_->joinable())
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "StreamSession joining readerThread\n";
|
LOG(DEBUG) << "StreamSession joining readerThread\n";
|
||||||
|
@ -145,10 +148,12 @@ bool StreamSession::send(const msg::message_ptr& message)
|
||||||
{
|
{
|
||||||
// TODO on exception: set active = false
|
// TODO on exception: set active = false
|
||||||
// LOG(INFO) << "send: " << message->type << ", size: " << message->getSize() << ", id: " << message->id << ", refers: " << message->refersTo << "\n";
|
// LOG(INFO) << "send: " << message->type << ", size: " << message->getSize() << ", id: " << message->id << ", refers: " << message->refersTo << "\n";
|
||||||
std::lock_guard<std::mutex> activeLock(activeMutex_);
|
std::lock_guard<std::mutex> socketLock(socketMutex_);
|
||||||
if (!active_)
|
{
|
||||||
return false;
|
std::lock_guard<std::mutex> activeLock(activeMutex_);
|
||||||
|
if (!active_)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
boost::asio::streambuf streambuf;
|
boost::asio::streambuf streambuf;
|
||||||
std::ostream stream(&streambuf);
|
std::ostream stream(&streambuf);
|
||||||
tv t;
|
tv t;
|
||||||
|
|
Loading…
Add table
Reference in a new issue