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 on generated filenames using timestamps #31

Closed
faustinoaq opened this issue Apr 30, 2018 · 7 comments
Closed

Race condition on generated filenames using timestamps #31

faustinoaq opened this issue Apr 30, 2018 · 7 comments

Comments

@faustinoaq
Copy link
Contributor

faustinoaq commented Apr 30, 2018

Hi @amberframework/contributors This issue is causing Travis Failures

Please, see amberframework/amber#775 (comment)

I suggest to fix it by using incremental names or wait at least 1.millisecond before generate migration file.

@faustinoaq
Copy link
Contributor Author

The incremental names approach was suggested by @vladfaust on #20

@faustinoaq
Copy link
Contributor Author

faustinoaq commented May 1, 2018

Another approach to solve this, is waiting at least 1.millisecond here before generating a migration file, like:

 sleep 1.millisecond
 migration_file = Micrate.create(ARGV.shift, Time.now, migrations_path) 
 puts "Created #{migration_file}"

on:

migration_file = Micrate.create(ARGV.shift, Time.now, migrations_path)
puts "Created #{migration_file}"

WDYT?

@robacarp
Copy link
Member

robacarp commented May 2, 2018

Sleeping before creating the file isn't going to prevent a race condition, it's just going to move it down the road a little bit. Generating a file with a timestamp, no matter how specific that timestamp, is always going to be subject to a race condition. Adding more digits to the migration timestamp isn't the answer either.

What about adding a "does this file exist?" check in the Micrate.create method? That will still be subject to a race condition when multiple migrations are generated concurrently, but running two commands consecutively will be safe.

@faustinoaq
Copy link
Contributor Author

Interesting idea, Thank you for sharing it, I going to try that as well 😅

@faustinoaq
Copy link
Contributor Author

faustinoaq commented May 13, 2018

Already fixed this on micrate v0.3.1. Still requires to be published on master. I didn't use master because has some breaking changes, so we would need to release micrate v0.4.0

Please see: https://github.com/amberframework/micrate/releases/tag/v0.3.1

@faustinoaq
Copy link
Contributor Author

Fixed by #33

@eliasjpr
Copy link
Contributor

Is this done? Would like to close this ticket and draft a new release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants