fix(replication): Handle errors instead of crashing. (#1757)

This commit is contained in:
Roy Jacobson 2023-08-29 15:29:40 +03:00 committed by GitHub
parent d964325f93
commit 254c86786e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -106,7 +106,11 @@ std::error_code JournalReader::EnsureRead(size_t num) {
// Try reading at least how much we need, but possibly more
uint64_t read;
SET_OR_RETURN(source_->ReadAtLeast(buf_.AppendBuffer(), remainder), read);
CHECK(read >= remainder);
// Happens on end of stream (for example, a too-small string buffer or a closed socket)
if (read < remainder) {
return make_error_code(errc::io_error);
}
buf_.CommitWrite(read);
return {};

View file

@ -666,7 +666,10 @@ error_code DflyShardReplica::StartStableSyncFlow(Context* cntx) {
ProactorBase* mythread = ProactorBase::me();
CHECK(mythread);
CHECK(Sock()->IsOpen());
if (!Sock()->IsOpen()) {
return std::make_error_code(errc::io_error);
}
sync_fb_ =
fb2::Fiber("shard_stable_sync_read", &DflyShardReplica::StableSyncDflyReadFb, this, cntx);
if (use_multi_shard_exe_sync_) {