reidmorrison / semantic_logger

Semantic Logger is a feature rich logging framework, and replacement for existing Ruby & Rails loggers.
https://logger.rocketjob.io/
Apache License 2.0
873 stars 124 forks source link

Intermittent `NameError`/`LoadError` when loading Rails environment #263

Closed maximevaillancourt closed 1 year ago

maximevaillancourt commented 1 year ago

Environment

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 https://github.com/rails/rails/issues/45600.

fxn commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.