Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Serializable transactions not working as intended #163

@derekchiang

Description

@derekchiang

I've created a repo that reproduces this issue: https://github.com/derekchiang/postgres-bug

Basically, I'm running some code in a serializable transaction like this (pseudocode):

BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE

const userCount = select count(*) from missions
if (userCount == 0) {
  insert into users default values
}

COMMIT

Now, when you run this transaction many times in parallel, you'd think that only one row would be created. However, as you can see from the test in the repo, more than 1 rows wound up getting created.

It's not clear to me whether this is a bug in Slonik or Postgres, or if I'm fundamentally misunderstanding something. But I thought I'd put it here in case it's an issue in Slonik.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions