aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/projectstore/projectstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-08-06 14:54:33 +0200
committerGitHub Enterprise <[email protected]>2024-08-06 14:54:33 +0200
commit1eaacecbdc540280d4ebd347c9f4b155799e6f89 (patch)
tree9ea10ecf4e6c5d8f83f1eb78ced37d2f3622d2d6 /src/zenserver/projectstore/projectstore.cpp
parentvalidate cbobject before iterating for attachments to avoid crash on malforme... (diff)
downloadzen-1eaacecbdc540280d4ebd347c9f4b155799e6f89.tar.xz
zen-1eaacecbdc540280d4ebd347c9f4b155799e6f89.zip
stop exceptions from leaking on threaded work (#102)
* catch exceptions in threaded work * don't abort all project file/chunk info fetch for single failure
Diffstat (limited to 'src/zenserver/projectstore/projectstore.cpp')
-rw-r--r--src/zenserver/projectstore/projectstore.cpp67
1 files changed, 44 insertions, 23 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp
index a542a6581..0f9481210 100644
--- a/src/zenserver/projectstore/projectstore.cpp
+++ b/src/zenserver/projectstore/projectstore.cpp
@@ -965,7 +965,7 @@ ProjectStore::Oplog::IterateChunks(std::span<Oid> ChunkIds,
break;
}
WorkLatch.AddCount(1);
- OptionalWorkerPool->ScheduleWork([&WorkLatch, ChunkIndex, &FileChunkIndexes, &FileChunkPaths, &AsyncCallback, &Result]() {
+ OptionalWorkerPool->ScheduleWork([this, &WorkLatch, ChunkIndex, &FileChunkIndexes, &FileChunkPaths, &AsyncCallback, &Result]() {
auto _ = MakeGuard([&WorkLatch]() { WorkLatch.CountDown(); });
if (Result.load() == false)
{
@@ -973,14 +973,21 @@ ProjectStore::Oplog::IterateChunks(std::span<Oid> ChunkIds,
}
size_t FileChunkIndex = FileChunkIndexes[ChunkIndex];
const std::filesystem::path& FilePath = FileChunkPaths[ChunkIndex];
- IoBuffer Payload = IoBufferBuilder::MakeFromFile(FilePath);
- if (Payload)
+ try
{
- if (!AsyncCallback(FileChunkIndex, Payload))
+ IoBuffer Payload = IoBufferBuilder::MakeFromFile(FilePath);
+ if (Payload)
{
- Result.store(false);
+ if (!AsyncCallback(FileChunkIndex, Payload))
+ {
+ Result.store(false);
+ }
}
}
+ catch (const std::exception& Ex)
+ {
+ ZEN_WARN("Exception caught when iterating file chunk {}, path '{}'. Reason: '{}'", FileChunkIndex, FilePath, Ex.what());
+ }
});
}
@@ -2838,20 +2845,27 @@ ProjectStore::GetProjectFiles(const std::string_view ProjectId,
FoundLog->IterateChunks(
Ids,
[&](size_t Index, const IoBuffer& Payload) {
- uint64_t Size = Payload.GetSize();
- if (WantsRawSizeField)
+ try
{
- uint64_t RawSize = Size;
- if (Payload.GetContentType() == ZenContentType::kCompressedBinary)
+ uint64_t Size = Payload.GetSize();
+ if (WantsRawSizeField)
+ {
+ uint64_t RawSize = Size;
+ if (Payload.GetContentType() == ZenContentType::kCompressedBinary)
+ {
+ IoHash __;
+ (void)CompressedBuffer::FromCompressed(SharedBuffer(Payload), __, RawSize);
+ }
+ RawSizes[Index] = RawSize;
+ }
+ if (WantsSizeField)
{
- IoHash __;
- (void)CompressedBuffer::FromCompressed(SharedBuffer(Payload), __, RawSize);
+ Sizes[Index] = Size;
}
- RawSizes[Index] = RawSize;
}
- if (WantsSizeField)
+ catch (const std::exception& Ex)
{
- Sizes[Index] = Size;
+ ZEN_WARN("Failed getting project file info for id {}. Reason: '{}'", Ids[Index], Ex.what());
}
return true;
},
@@ -2955,20 +2969,27 @@ ProjectStore::GetProjectChunkInfos(const std::string_view ProjectId,
(void)FoundLog->IterateChunks(
Hashes,
[&](size_t Index, const IoBuffer& Chunk) -> bool {
- uint64_t Size = Chunk.GetSize();
- if (WantsRawSizeField)
+ try
{
- uint64_t RawSize = Size;
- if (Chunk.GetContentType() == ZenContentType::kCompressedBinary)
+ uint64_t Size = Chunk.GetSize();
+ if (WantsRawSizeField)
+ {
+ uint64_t RawSize = Size;
+ if (Chunk.GetContentType() == ZenContentType::kCompressedBinary)
+ {
+ IoHash __;
+ (void)CompressedBuffer::FromCompressed(SharedBuffer(Chunk), __, RawSize);
+ }
+ RawSizes[Index] = RawSize;
+ }
+ if (WantsSizeField)
{
- IoHash __;
- (void)CompressedBuffer::FromCompressed(SharedBuffer(Chunk), __, RawSize);
+ Sizes[Index] = Size;
}
- RawSizes[Index] = RawSize;
}
- if (WantsSizeField)
+ catch (const std::exception& Ex)
{
- Sizes[Index] = Size;
+ ZEN_WARN("Failed getting chunk info for id {}. Reason: '{}'", Ids[Index], Ex.what());
}
return true;
},