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 between env and defaults when using LITESTACK_DATA_PATH with dotenv gem #91

Open
silva96 opened this issue Jan 30, 2024 · 3 comments

Comments

@silva96
Copy link

silva96 commented Jan 30, 2024

If I add LITESTACK_DATA_PATH="./storage" to my .env it is picked up after the litestack initializes some classes so it uses the default path to create the databases, but later on, it tries to find databases files in LITESTACK_DATA_PATH (i think)

See this screenshot where I paused execution.

CleanShot 2024-01-29 at 23 37 12@2x

This leads to the app having sqlite3 files in 2 different parts:

CleanShot 2024-01-29 at 23 59 45@2x

@rossta
Copy link
Contributor

rossta commented Jan 31, 2024

I have experienced the same behavior. Litestack should probably provide a runtime configuration code path; currently, the LITESTACK_DATA_PATH and other configuration settings are loaded at boot time.

My workaround in Rails is to load dotenv at the top of application.rb, per the dotenv README.

@silva96
Copy link
Author

silva96 commented Feb 1, 2024

That's a good one @rossta , with that comment in the readme at least, it would work for most users in the future.

@christopher-b
Copy link

@rossta's suggestion seems to work for some modules (database), but not all (queue, metrics). It seems that a more reliable solution is to provide hard-coded paths in the configs for these modules:

# config/litemetric.yml:
development:
  path: ./storage/litestack/development/metrics.sqlite3
test:
  path: ./storage/litestack/test/metrics.sqlite3
production:
  path: ./storage/litestack/production/metrics.sqlite3
# config/litequeue.yml
development:
  path: ./storage/litestack/development/queue.sqlite3
test:
  path: ./storage/litestack/test/queue.sqlite3
production:
  path: ./storage/litestack/production/queue.sqlite3

It also seems that these database files are being initialized even if the modules are not being used in the application. It would be nice to only have them initialized if they are needed.

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

No branches or pull requests

3 participants