Skip to content

Commit

Permalink
Fix synchronization issue with console.
Browse files Browse the repository at this point in the history
If a query couldn't be processed, client and server could get
synchronized.
  • Loading branch information
rsmmr committed Jan 15, 2024
1 parent d273b26 commit b4b0299
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/io/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,16 @@ void ConsoleServer::Implementation::query(const socket::Remote& remote, const st
if ( subscription && *subscription == query::SubscriptionType::Snapshots )
pending->remote << std::endl;

if ( ! pending->remote ) {
// Cancel query on error, but still try to get
// the error message across.
sendError(pending->remote, frmt("console send failed: {}", *pending->remote.error()));
if ( ! pending->remote )
// Cancel query on error.
pending->done_cv.notify_all();
}
},

.callback_done =
[pending](query::ID id, bool regular_shutdown) {
std::unique_lock<std::mutex> lock(pending->done_mutex);
pending->remote << std::endl;
sendEndOfMessage(pending->remote);
pending->done_cv.notify_all();
}};

Expand All @@ -256,7 +254,6 @@ void ConsoleServer::Implementation::query(const socket::Remote& remote, const st
});

pending->done_cv.wait(lock);
sendEndOfMessage(pending->remote);

if ( auto err = pending->remote.error() )
logger()->warn("console send failed: {}", *err);
Expand Down

0 comments on commit b4b0299

Please sign in to comment.