aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexvru <alexvru@ydb.tech>2023-04-04 11:22:06 +0300
committeralexvru <alexvru@ydb.tech>2023-04-04 11:22:06 +0300
commitb1096383308a7d5c9906a5395338d04f0d814c5f (patch)
treef4b48e92b26c4fc4b9ca28f7de916c6972cef43b
parentea3bc32778a248012cdd957da62448b65bdb38f6 (diff)
downloadydb-b1096383308a7d5c9906a5395338d04f0d814c5f.tar.gz
Fix coro tx bug
-rw-r--r--ydb/core/blob_depot/coro_tx.cpp52
1 files changed, 22 insertions, 30 deletions
diff --git a/ydb/core/blob_depot/coro_tx.cpp b/ydb/core/blob_depot/coro_tx.cpp
index 84caf07bfc1..871292bd6b7 100644
--- a/ydb/core/blob_depot/coro_tx.cpp
+++ b/ydb/core/blob_depot/coro_tx.cpp
@@ -1,5 +1,10 @@
#include "coro_tx.h"
+#include <util/system/sanitizers.h>
+#include <util/system/type_name.h>
+#include <util/system/info.h>
+#include <util/system/protect.h>
+
namespace NKikimr::NBlobDepot {
thread_local TCoroTx *TCoroTx::Current = nullptr;
@@ -12,10 +17,15 @@ namespace NKikimr::NBlobDepot {
END_CORO
};
+ static const size_t PageSize = NSystemInfo::GetPageSize();
+
+ static size_t AlignStackSize(size_t size) {
+ size += PageSize - (size & PageSize - 1) & PageSize - 1;
#ifndef NDEBUG
- static constexpr ui64 StackSentinel = 0x8E0CDBFD41F04520;
- static constexpr size_t NumStackSentinels = 8;
+ size += PageSize;
#endif
+ return size;
+ }
class TCoroTx::TContext : public ITrampoLine {
TMappedAllocation Stack;
@@ -28,30 +38,23 @@ namespace NKikimr::NBlobDepot {
std::function<void()> Body;
bool Finished = false;
+ bool Aborted = false;
public:
TContext(TTokens&& tokens, std::function<void()>&& body)
- : Stack(65536)
+ : Stack(AlignStackSize(65536))
, Context({this, TArrayRef(Stack.Begin(), Stack.End())})
, Tokens(std::move(tokens))
, Body(std::move(body))
{
-#ifndef NDEBUG
- char *p;
-# if STACK_GROW_DOWN
- p = Stack.Begin();
-# else
- p = Stack.End() - sizeof(StackSentinel) * NumStackSentinels;
-# endif
- for (size_t i = 0; i < NumStackSentinels; ++i) {
- memcpy(p + i * sizeof(StackSentinel), &StackSentinel, sizeof(StackSentinel));
- }
+#if !defined(NDEBUG)
+ ProtectMemory(STACK_GROW_DOWN ? Stack.Begin() : Stack.End() - PageSize, PageSize, EProtectMemoryMode::PM_NONE);
#endif
}
~TContext() {
if (!Finished) {
- Finished = true;
+ Aborted = true;
Resume();
}
}
@@ -62,25 +65,11 @@ namespace NKikimr::NBlobDepot {
TExceptionSafeContext returnContext;
Y_VERIFY(!BackContext);
BackContext = &returnContext;
+ Y_VERIFY_DEBUG(CurrentTx() || Aborted);
returnContext.SwitchTo(&Context);
Y_VERIFY(BackContext == &returnContext);
BackContext = nullptr;
- // validate stack
-#ifndef NDEBUG
- char *p;
-# if STACK_GROW_DOWN
- p = Stack.Begin();
-# else
- p = Stack.End() - sizeof(StackSentinel) * NumStackSentinels;
-# endif
- for (size_t i = 0; i < NumStackSentinels; ++i) {
- ui64 temp;
- memcpy(&temp, p + i * sizeof(StackSentinel), sizeof(StackSentinel));
- Y_VERIFY(StackSentinel == temp);
- }
-#endif
-
Y_VERIFY(Outcome != EOutcome::UNSET);
return Outcome;
}
@@ -90,13 +79,16 @@ namespace NKikimr::NBlobDepot {
Outcome = outcome;
Y_VERIFY(BackContext);
Context.SwitchTo(BackContext);
- if (IsExpired() || Finished) {
+ if (IsExpired()) {
throw TExDead();
}
}
private:
bool IsExpired() const {
+ if (Aborted) {
+ return true;
+ }
for (auto& token : Tokens) {
if (token.expired()) {
return true;