Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition with String_Split causes failure #23

Closed
rlaveycal opened this issue Nov 12, 2021 · 0 comments · Fixed by #24
Closed

Race condition with String_Split causes failure #23

rlaveycal opened this issue Nov 12, 2021 · 0 comments · Fixed by #24

Comments

@rlaveycal
Copy link
Contributor

Version: betr-io/mssql v0.2.3

I've written a module that creates a login and a user. I set the count to 2 in order. The second user fails with the output below.

module.sql_readwrite_user[1].mssql_login.user: Creation complete after 1s [id=sqlserver://foo.database.windows.net:1433/svc_calorders_readwrite_2]
module.sql_readwrite_user[0].mssql_login.user: Creation complete after 1s [id=sqlserver://foo.database.windows.net:1433/svc_calorders_readwrite_1]
module.sql_readwrite_user[1].mssql_user.user: Creating...
module.sql_readwrite_user[0].mssql_user.user: Creating...
module.sql_readwrite_user[1].mssql_user.user: Creation complete after 1s [id=sqlserver://foo.database.windows.net:1433/MYDB/svc_calorders_readwrite_2]
╷
│ Error: unable to create user [MYDB].[svc_calorders_readwrite_1]: mssql: There is already an object named 'String_Split' in the database.
│ 
│   with module.sql_readwrite_user[0].mssql_user.user,
│   on sql_login/main.tf line 24, in resource "mssql_user" "user":
│   24: resource "mssql_user" "user" {

This seems to be related to #17. It appears to be a race condition where the 2nd concurrent user resource tries to create the split function but then fails as it now exists.

Should the function check/creation be in transaction, or the "exists" test should be repeated inside the create statement?

rlaveycal added a commit to rlaveycal/terraform-provider-mssql that referenced this issue Nov 12, 2021
Only create string_split if DB level doesn't have it

Signed-off-by: Richard Lavey <richard.lavey@calastone.com>
@magne magne closed this as completed in #24 Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant