Skip to content

Avoidable Concurrency Exception? #201

@ylbillyli

Description

@ylbillyli

I run into situation where two event subscribers firing commands against the same aggregate in parallel (because eventflow's event dispatcher dispatch events to subscriber in parallel using "WhenAll()"), which was causing a concurrency exception. Although they are handled fine by the retry, these commands involve calling other integrated systems which cannot be roll-back/redo ending up duplicated operations.

This might be best solved by designing the integration strategy better to external systems, but it is too late for our project and I have solved the problem by using the "Keyed" AsyncLocker in http://stackoverflow.com/questions/31138179/asynchronous-locking-based-on-a-key and modified the command bus class adding a lock around the Loading of Aggregate until it is committed using the AggregateId as the locking key, such that multiple commands firing against the same aggregate will be synchronized.

image

My main argument here is, when multiple commands firing against the same aggregate at the same time which would guarantee a race condition, could acutally be avoided by thread safe locking. It make sense to me to prevent multiple threads modifying the same aggregate at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions