Skip to content

Threading issues with asynchronous messaging to inactive subscription #64

@dalijap

Description

@dalijap

There are threading issues in asynchronous messaging with inactive subscription.

Namely code in Post methods checks whether subscription is active before invoking subscription method

TEventBus.Post

for LSubscription in LSubscriptions do begin
  if (LSubscription.Context <> AChannel) or (not LSubscription.Active) then Continue;
  PostToChannel(LSubscription, AMessage, LIsMainThread);

for LSubscription in LSubscriptions do begin
  if not LSubscription.Active then Continue;
  PostToSubscription(LSubscription, AEvent, LIsMainThread);

But, depending on threading mode PostToChannel and PostToSubscription methods can invoke subscription method asynchronously with TThread.Queue or TTask.Run or TThread.CreateAnonymousThread

During that time subscription can get inactive and that can cause crashes by calling subscription method on dead object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions