Skip to content

Schema creation within sqlserver__get_test_sql macro is not concurrency-safe #839

Description

@jay-taylor-ac

This part of the sqlserver__get_test_sql macro that creates schemas is not concurrency-safe:

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ target.schema }}')
BEGIN
  EXEC('CREATE SCHEMA [{{ target.schema }}]')
END

This results in a race condition when the number of threads are more than 1, which often results in the following error:

There is already an object named 'my_schema' in the database.

We have found this to be problematic during CI runs, where a new schema is created for each PR, often resulting in the first CI run failing due to the race condition and us needing to rerun the pipeline again.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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