Skip to content

Is there a race condition bug? #13

Description

@godhand4826

I was wondering about how this project encapsulate the relational database transaction.
The definition of good repository interface (/internal/app/service/barter/interface.go/GoodRepository) might can't get away from race condition. Before using UpdateGoods, there must be a GetGoodByID somewhere. Since the read and write are not in the same transaction, so the state is not protected by the relational database.

let's have a look at /internal/app/service/barter/exchange_service.go/(*BarterService).ExchangeGoods

  • let's say the initial state is...
    • a good X belongs to trader A
    • a good Y belongs to trader B
    • a good Z belongs to trader C
  • trader A launch two exchange request XY and XZ
    Imgur
  • the final state is...
    • a good X belongs to trader C
    • a good Y belongs to trader A
    • a good Z belongs to trader A

I'm might be wrong because I'm not really execute it. I'm just simulate the execution in my head.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions