Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Intermittent NameError/LoadError when loading Rails environment #263

Closed
maximevaillancourt opened this issue Jan 30, 2023 · 3 comments
Closed

Comments

@maximevaillancourt
Copy link

maximevaillancourt commented Jan 30, 2023

Environment

  • Ruby 3.2.0
  • Rails 7.0.4.1 (Zeitwerk 2.6.6)
  • Bootsnap 1.15.0
  • semantic_logger 4.12.0 via rails_semantic_logger 4.11.0

Expected Behavior

Loading the Rails environment succeeds when semantic_logger gem is used in a Rails app.

Actual Behavior

Loading the Rails environment fails intermittently with either NameError: uninitialized constant <constant> (when Bootsnap is enabled) or LoadError: cannot such such file -- <file> (when Bootsnap is disabled). The constants that show up are not related to semantic_logger: they're often constants from other gems.

I'm currently unable to reproduce the bug reliably. We've seen this bug happen intermittently in GitHub Actions the most (where our CI suite runs on x64-based Ubuntu 22.04 VMs), and only one time locally on an M1-powered MacBook. Removing the rails_semantic_logger gem entirely fully prevents NameError/LoadError from showing up.

Full investigation thread available in this other GitHub issue—the most salient insight is in this comment.

Might also be the root cause of rails/rails#45600.

@fxn
Copy link

fxn commented Feb 2, 2023

This is a very weird error, if all caches are disabled (Bootsnap and Spring) so we can go to root of the matter, we find that the application raises a LoadError for active_admin.rb, and its directory is in $LOAD_PATH. Very odd.

No idea how could this gem be related, the only observation is that without this gem, the error can be reproduced (not consistently, but given a few attempts), and without this gem the error cannot be triggered.

Disclaimer, I just participated in the research, don't have access to the application.

@reidmorrison
Copy link
Owner

We removed Spring from all of our projects because it causes more problems than it solves. As of Ruby 2.7 it does not appear to make any visible difference either.

@reidmorrison
Copy link
Owner

In Semantic Logger v4.13 it replaces most autoload calls to hard requires. It may help bootsnap out since most files are no loaded on demand.

Repository owner locked and limited conversation to collaborators Mar 26, 2023
@reidmorrison reidmorrison converted this issue into discussion #266 Mar 26, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants