diff options
| author | zousar <[email protected]> | 2025-08-05 14:58:08 -0600 |
|---|---|---|
| committer | zousar <[email protected]> | 2025-08-05 14:58:08 -0600 |
| commit | 7ddededb31c9b3415d4d85f0b284e5bf45c723b9 (patch) | |
| tree | e908f97766720550b7d3d4e8553b3c83132c0735 /src | |
| parent | xmake precommit (diff) | |
| parent | de/stringbuilder safety (#456) (diff) | |
| download | zen-7ddededb31c9b3415d4d85f0b284e5bf45c723b9.tar.xz zen-7ddededb31c9b3415d4d85f0b284e5bf45c723b9.zip | |
Merge branch 'main' into zs/put-overwrite-policy
Diffstat (limited to 'src')
| -rw-r--r-- | src/zencore/callstack.cpp | 25 | ||||
| -rw-r--r-- | src/zencore/thread.cpp | 10 | ||||
| -rw-r--r-- | src/zencore/zencore.cpp | 9 | ||||
| -rw-r--r-- | src/zenhttp/packageformat.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/main.cpp | 16 | ||||
| -rw-r--r-- | src/zenstore/cache/cachedisklayer.cpp | 51 | ||||
| -rw-r--r-- | src/zenutil/parallelwork.cpp | 8 |
7 files changed, 85 insertions, 36 deletions
diff --git a/src/zencore/callstack.cpp b/src/zencore/callstack.cpp index 9b06d4575..b22f2ec1f 100644 --- a/src/zencore/callstack.cpp +++ b/src/zencore/callstack.cpp @@ -179,19 +179,26 @@ FormatCallstack(const CallstackFrames* Callstack, StringBuilderBase& SB, std::st bool First = true; for (const std::string& Symbol : GetFrameSymbols(Callstack)) { - if (!First) + try { - SB.Append("\n"); - } - else - { - First = false; + if (!First) + { + SB.Append("\n"); + } + else + { + First = false; + } + if (!Prefix.empty()) + { + SB.Append(Prefix); + } + SB.Append(Symbol); } - if (!Prefix.empty()) + catch (const std::exception&) { - SB.Append(Prefix); + break; } - SB.Append(Symbol); } } diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index ab7e6857a..0d5ad6091 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -80,8 +80,10 @@ SetNameInternal(DWORD thread_id, const char* name) void SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName) { - StringBuilder<256> ThreadNameZ; - ThreadNameZ << ThreadName; + constexpr std::string_view::size_type MaxThreadNameLength = 255; + std::string_view LimitedThreadName = ThreadName.substr(0, MaxThreadNameLength); + StringBuilder<MaxThreadNameLength + 1> ThreadNameZ; + ThreadNameZ << LimitedThreadName; const int ThreadId = GetCurrentThreadId(); #if ZEN_WITH_TRACE @@ -95,8 +97,8 @@ SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName) if (SetThreadDescriptionFunc) { - WideStringBuilder<256> ThreadNameW; - Utf8ToWide(ThreadName, ThreadNameW); + WideStringBuilder<MaxThreadNameLength + 1> ThreadNameW; + Utf8ToWide(LimitedThreadName, ThreadNameW); SetThreadDescriptionFunc(::GetCurrentThread(), ThreadNameW.c_str()); } diff --git a/src/zencore/zencore.cpp b/src/zencore/zencore.cpp index 82d28c0e3..51e06ae14 100644 --- a/src/zencore/zencore.cpp +++ b/src/zencore/zencore.cpp @@ -124,7 +124,14 @@ AssertImpl::ExecAssert(const char* Filename, int LineNumber, const char* Functio AssertImpl* AssertImpl = CurrentAssertImpl; while (AssertImpl) { - AssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg, Callstack); + try + { + AssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg, Callstack); + } + catch (const std::exception&) + { + // Just keep exception silent - we don't want exception thrown from assert callbacks + } AssertImpl = AssertImpl->NextAssertImpl; } ThrowAssertException(Filename, LineNumber, FunctionName, Msg, Callstack); diff --git a/src/zenhttp/packageformat.cpp b/src/zenhttp/packageformat.cpp index 9d423ecbc..0b7848f79 100644 --- a/src/zenhttp/packageformat.cpp +++ b/src/zenhttp/packageformat.cpp @@ -576,7 +576,7 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint if (!MalformedAttachments.empty()) { - StringBuilder<1024> SB; + ExtendableStringBuilder<1024> SB; SB << (uint64_t)MalformedAttachments.size() << " malformed attachments in package message:\n"; for (const auto& It : MalformedAttachments) { diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index b0d945814..6d9a478be 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -117,6 +117,14 @@ ZenEntryPoint::Run() ServerState.Initialize(); ServerState.Sweep(); + auto NotifyReady = [&] { + if (!m_ServerOptions.ChildId.empty()) + { + NamedEvent ParentEvent{m_ServerOptions.ChildId}; + ParentEvent.Set(); + } + }; + uint32_t AttachSponsorProcessRetriesLeft = 3; ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(m_ServerOptions.BasePort); while (Entry) @@ -155,6 +163,7 @@ ZenEntryPoint::Run() // Sponsor processes are checked every second, so 2 second wait time should be enough if (Entry->AddSponsorProcess(m_ServerOptions.OwnerPid, 2000)) { + NotifyReady(); std::exit(0); } if (AttachSponsorProcessRetriesLeft-- > 0) @@ -294,12 +303,7 @@ ZenEntryPoint::Run() Server.SetIsReadyFunc([&] { m_LockFile.Update(MakeLockData(true), Ec); - - if (!m_ServerOptions.ChildId.empty()) - { - NamedEvent ParentEvent{m_ServerOptions.ChildId}; - ParentEvent.Set(); - } + NotifyReady(); }); Server.Run(); diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp index 1ebb8f144..60475e30c 100644 --- a/src/zenstore/cache/cachedisklayer.cpp +++ b/src/zenstore/cache/cachedisklayer.cpp @@ -403,11 +403,20 @@ BucketManifestSerializer::ParseManifest(RwLock::ExclusiveLockScope& Buck Stopwatch Timer; const auto _ = MakeGuard([&] { ZEN_INFO("parsed store manifest '{}' in {}", ManifestPath, NiceTimeSpanMs(Timer.GetElapsedTimeMs())); }); - const uint64_t Count = Manifest["Count"sv].AsUInt64(0); + const uint64_t Count = Manifest["Count"sv].AsUInt64(0); + CbArrayView KeyArray = Manifest["Keys"sv].AsArrayView(); + if (KeyArray.Num() != Count) + { + ZEN_WARN("Mismatch in size between 'Keys' ({}) array size and 'Count' ({}) in {}, skipping metadata", + KeyArray.Num(), + Count, + ManifestPath); + return; + } + std::vector<PayloadIndex> KeysIndexes; KeysIndexes.reserve(Count); - CbArrayView KeyArray = Manifest["Keys"sv].AsArrayView(); for (CbFieldView& KeyView : KeyArray) { if (auto It = Index.find(KeyView.AsHash()); It != Index.end()) @@ -422,19 +431,43 @@ BucketManifestSerializer::ParseManifest(RwLock::ExclusiveLockScope& Buck size_t KeyIndexOffset = 0; CbArrayView TimeStampArray = Manifest["Timestamps"].AsArrayView(); - for (CbFieldView& TimeStampView : TimeStampArray) + if (KeysIndexes.size() != TimeStampArray.Num()) { - const PayloadIndex KeyIndex = KeysIndexes[KeyIndexOffset++]; - if (KeyIndex) + ZEN_WARN("Mismatch in size between 'Keys' ({}) and 'Timestamps' ({}) arrays in {}, skipping timestamps", + KeysIndexes.size(), + TimeStampArray.Num(), + ManifestPath); + } + else + { + for (CbFieldView& TimeStampView : TimeStampArray) { - AccessTimes[KeyIndex] = TimeStampView.AsInt64(); + const PayloadIndex KeyIndex = KeysIndexes[KeyIndexOffset++]; + if (KeyIndex) + { + AccessTimes[KeyIndex] = TimeStampView.AsInt64(); + } } } KeyIndexOffset = 0; CbArrayView RawHashArray = Manifest["RawHash"].AsArrayView(); CbArrayView RawSizeArray = Manifest["RawSize"].AsArrayView(); - if (RawHashArray.Num() == RawSizeArray.Num()) + if (RawHashArray.Num() != KeysIndexes.size()) + { + ZEN_WARN("Mismatch in size between 'Keys' ({}) and 'RawHash' ({}) arrays in {}, skipping meta data", + KeysIndexes.size(), + RawHashArray.Num(), + ManifestPath); + } + else if (RawSizeArray.Num() != KeysIndexes.size()) + { + ZEN_WARN("Mismatch in size between 'Keys' ({}) and 'RawSize' ({}) arrays in {}, skipping meta data", + KeysIndexes.size(), + RawSizeArray.Num(), + ManifestPath); + } + else { auto RawHashIt = RawHashArray.CreateViewIterator(); auto RawSizeIt = RawSizeArray.CreateViewIterator(); @@ -459,10 +492,6 @@ BucketManifestSerializer::ParseManifest(RwLock::ExclusiveLockScope& Buck RawSizeIt++; } } - else - { - ZEN_WARN("Mismatch in size between 'RawHash' and 'RawSize' arrays in {}, skipping meta data", ManifestPath); - } } Oid diff --git a/src/zenutil/parallelwork.cpp b/src/zenutil/parallelwork.cpp index aa806438b..1edca5050 100644 --- a/src/zenutil/parallelwork.cpp +++ b/src/zenutil/parallelwork.cpp @@ -33,6 +33,7 @@ ParallelWork::~ParallelWork() "ParallelWork disposed without explicit wait for completion, likely caused by an exception, waiting for dispatched threads " "to complete"); m_PendingWork.CountDown(); + m_DispatchComplete = true; } m_PendingWork.Wait(); ptrdiff_t RemainingWork = m_PendingWork.Remaining(); @@ -82,10 +83,9 @@ void ParallelWork::Wait(int32_t UpdateIntervalMS, UpdateCallback&& UpdateCallback) { ZEN_ASSERT(!m_DispatchComplete); - m_DispatchComplete = true; - ZEN_ASSERT(m_PendingWork.Remaining() > 0); m_PendingWork.CountDown(); + m_DispatchComplete = true; while (!m_PendingWork.Wait(UpdateIntervalMS)) { @@ -99,10 +99,10 @@ void ParallelWork::Wait() { ZEN_ASSERT(!m_DispatchComplete); - m_DispatchComplete = true; - ZEN_ASSERT(m_PendingWork.Remaining() > 0); m_PendingWork.CountDown(); + m_DispatchComplete = true; + m_PendingWork.Wait(); RethrowErrors(); |