Skip to content

Commit ddc16f2

Browse files
authored
Fix segv in case of using schedule outside of actorsystem (#14469)
1 parent 2c20d41 commit ddc16f2

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

ydb/library/actors/core/defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace NActors {
3232
static constexpr TPoolWeight DefPoolWeight = 32;
3333
static constexpr TPoolWeight MaxPoolWeight = 1024;
3434

35-
using TWorkerId = i16;
35+
using TWorkerId = ui16;
3636
static constexpr TWorkerId WorkerBits = 11;
3737
static constexpr TWorkerId MaxWorkers = 1 << WorkerBits;
3838

ydb/library/actors/core/executor_pool_basic.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,28 +354,29 @@ namespace NActors {
354354
}
355355

356356
void TBasicExecutorPool::ScheduleActivationExLocalQueue(TMailbox* mailbox, ui64 revolvingWriteCounter) {
357-
if (TlsThreadContext && TlsThreadContext->Pool() == this && TlsThreadContext->WorkerId() >= 0) {
357+
if (TlsThreadContext && TlsThreadContext->Pool() == this) {
358+
TWorkerId workerId = TlsThreadContext->WorkerId();
358359
if (++TlsThreadContext->LocalQueueContext.WriteTurn < TlsThreadContext->LocalQueueContext.LocalQueueSize) {
359-
LocalQueues[TlsThreadContext->WorkerId()].push(mailbox->Hint);
360+
LocalQueues[workerId].push(mailbox->Hint);
360361
return;
361362
}
362363
if (ActorSystemProfile != EASProfile::Default) {
363364
TAtomic x = AtomicGet(Semaphore);
364365
TSemaphore semaphore = TSemaphore::GetSemaphore(x);
365366
if constexpr (NFeatures::TLocalQueuesFeatureFlags::UseIfAllOtherThreadsAreSleeping) {
366367
if (semaphore.CurrentSleepThreadCount == semaphore.CurrentThreadCount - 1 && semaphore.OldSemaphore == 0) {
367-
if (LocalQueues[TlsThreadContext->WorkerId()].empty()) {
368-
LocalQueues[TlsThreadContext->WorkerId()].push(mailbox->Hint);
368+
if (LocalQueues[workerId].empty()) {
369+
LocalQueues[workerId].push(mailbox->Hint);
369370
return;
370371
}
371372
}
372373
}
373374

374375
if constexpr (NFeatures::TLocalQueuesFeatureFlags::UseOnMicroburst) {
375376
if (semaphore.OldSemaphore >= semaphore.CurrentThreadCount) {
376-
if (LocalQueues[TlsThreadContext->WorkerId()].empty() && TlsThreadContext->LocalQueueContext.WriteTurn < 1) {
377+
if (LocalQueues[workerId].empty() && TlsThreadContext->LocalQueueContext.WriteTurn < 1) {
377378
TlsThreadContext->LocalQueueContext.WriteTurn++;
378-
LocalQueues[TlsThreadContext->WorkerId()].push(mailbox->Hint);
379+
LocalQueues[workerId].push(mailbox->Hint);
379380
return;
380381
}
381382
}
@@ -519,8 +520,8 @@ namespace NActors {
519520
if (deadline < current)
520521
deadline = current;
521522

522-
if (auto sharedPool = TlsThreadContext->SharedPool()) {
523-
sharedPool->Schedule(deadline, ev, cookie, workerId);
523+
if (TlsThreadContext && TlsThreadContext->IsShared()) {
524+
TlsThreadContext->SharedPool()->Schedule(deadline, ev, cookie, workerId);
524525
} else {
525526
Y_DEBUG_ABORT_UNLESS(workerId < MaxFullThreadCount);
526527
ScheduleWriters[workerId].Push(deadline.MicroSeconds(), ev.Release(), cookie);
@@ -529,8 +530,8 @@ namespace NActors {
529530

530531
void TBasicExecutorPool::Schedule(TDuration delta, TAutoPtr<IEventHandle> ev, ISchedulerCookie* cookie, TWorkerId workerId) {
531532
const auto deadline = ActorSystem->Monotonic() + delta;
532-
if (auto sharedPool = TlsThreadContext->SharedPool()) {
533-
sharedPool->Schedule(deadline, ev, cookie, workerId);
533+
if (TlsThreadContext && TlsThreadContext->IsShared()) {
534+
TlsThreadContext->SharedPool()->Schedule(deadline, ev, cookie, workerId);
534535
} else {
535536
Y_DEBUG_ABORT_UNLESS(workerId < MaxFullThreadCount);
536537
ScheduleWriters[workerId].Push(deadline.MicroSeconds(), ev.Release(), cookie);

0 commit comments

Comments
 (0)