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

Infinite recursion in SourcemappingUrlProcessor #481

Closed
tomhughes opened this issue Nov 16, 2021 · 15 comments
Closed

Infinite recursion in SourcemappingUrlProcessor #481

tomhughes opened this issue Nov 16, 2021 · 15 comments

Comments

@tomhughes
Copy link

We have an asset in our project that appears to be causing an infinite recursion in the new SourcemappingUrlProcessor with a stack that looks like:

/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/sourcemapping_url_processor.rb:15:in `block in call'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/sourcemapping_url_processor.rb:12:in `gsub'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/sourcemapping_url_processor.rb:12:in `call'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:33:in `call'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/context.rb:116:in `load'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/context.rb:144:in `depend_on_asset'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/context.rb:184:in `link_asset'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/context.rb:27:in `compute_asset_path'
/usr/local/share/gems/ruby/3.0.0/gems/actionview-6.1.4.1/lib/action_view/helpers/asset_url_helper.rb:203:in `asset_path'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/sourcemapping_url_processor.rb:18:in `block in call'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/sourcemapping_url_processor.rb:12:in `gsub'
/usr/local/share/gems/ruby/3.0.0/gems/sprockets-rails-3.4.0/lib/sprockets/rails/sourcemapping_url_processor.rb:12:in `call'

which then repeats over and over.

The asset that triggers it is https://github.com/Johann-S/bs-custom-file-input/blob/master/dist/bs-custom-file-input.js and although the url map comment seems sensible the preprocessor gets reinvoked for bs-custom-file-input.js rather than bs-custom-file-input.js.map when build the asset path.

@esb
Copy link

esb commented Nov 16, 2021

+1 Got the same problem yesterday and had to rollback to the previous version. I haven't had time to identify the asset that triggered the bug, but I'm getting the same type of recursion.

@chubchenko
Copy link

+1

@tomhughes
Copy link
Author

This is the call where the problem starts:

/usr/local/share/gems/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/context.rb:144:in `depend_on_asset'

It is called with bs-custom-file-input.js.map but when it calls resolve on that it gets a URI for bs-custom-file-input.js which it then tries to load.

@ebenenglish
Copy link

Same issue after updating to 3.4.0, reverting to 3.2.2 solved the problem.

Arie added a commit to Arie/serveme that referenced this issue Nov 17, 2021
Pin sprockets-rails due to rails/sprockets-rails#481
@rafaelfranca
Copy link
Member

@dhh this seems to be caused by your change. I tried to understand how to fix but unfortunately I could not understand the requirements.

@dhh
Copy link
Member

dhh commented Nov 22, 2021

I'll investigate and fix.

@dhh
Copy link
Member

dhh commented Nov 22, 2021

The requirement is that sourceMappingURL needs to refer to digested assets, otherwise it's not going to work when those comments are added by esbuild/webpack/etc, because Sprockets will digest all assets in production. It's the same issue as with CSS url().

dhh added a commit that referenced this issue Nov 22, 2021
This will prevent the recursion issue noticed in #481.
@dhh
Copy link
Member

dhh commented Nov 22, 2021

Trying to figure out exactly how this is triggered. How are you including bs-custom-file-input.js? Is it a local file?

Can you try #483 to see if it resolves the issue?

@tomhughes
Copy link
Author

It's just installed in node_modules and then pulled into app/assets/javascripts/application.js with:

//= require bs-custom-file-input
//= require bs-custom-file-input-init

@tomhughes
Copy link
Author

I've checked and #483 makes no difference but then I wouldn't expect it to as there is no path involved here.

@dhh
Copy link
Member

dhh commented Nov 22, 2021

Hmm, I figured the issue was that we were running the same replacement more than once. But guess not. I'll try to replicate your setup.

@dhh
Copy link
Member

dhh commented Nov 22, 2021

Found the issue. It's a bug deeper in Sprockets. If you do context.resolve("a/source.js.map") you'll correctly get a/source.js.map back. If you do context.resolve("a/b/source.js.map"), you'll incorrectly get a/b/source.js back instead 🤔. Vaguely remember hitting this bug before in another issue, but don't recall the specifics.

Anyway, I can work around this for now, but would be nicer to fix the underlying issue!

@dhh
Copy link
Member

dhh commented Nov 22, 2021

@tomhughes Can you give #484 a try?

@dhh
Copy link
Member

dhh commented Nov 22, 2021

Confirmed fixed on the reproduction and released as 3.4.1. Thanks for the help tracking this down!

Solving the underlying and long-standing issue with sprocket lookups on 2+ deep nesting is still pending. If anyone is interested in pursuing, please do.

@dhh dhh closed this as completed Nov 22, 2021
@tomhughes
Copy link
Author

Yes that seems to have fixed it for us as well, thanks.

Arie added a commit to Arie/serveme that referenced this issue Jul 26, 2022
Arie added a commit to Arie/serveme that referenced this issue Feb 21, 2023
Pin sprockets-rails due to rails/sprockets-rails#481
Arie added a commit to Arie/serveme that referenced this issue Feb 21, 2023
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

6 participants