Skip to content

Conversation

@ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Dec 15, 2025

What does this PR do?

This PR fixes a regression introduced in #4999: In that PR we added a call to Bundler.bin_path but did not realize that bundler not only returns the path BUT CRUCIALLY it makes sure the path exists by going as far as trying to create it if it doesn't.

If the directory does not exist, and the application directory is read-only (or the app does not have enough permissions), the application will fail with:

There was an error while trying to write to (directory). It is likely that you need to grant write permissions for that path. (Bundler::PermissionError)

Fixes #5137

Motivation:

Fix a regression introduced in #4999 that shipped in v2.23.0.

Change log entry

Yes. Fix profiler causing Bundler::PermissionError

Additional Notes:

The bundler's bin_path method has had a similar
behavior/implementation for 15+ years:

So we should be fine in replicating its behavior + having a test that checks we're matching it.

Worst case, we get CodeProvenance slightly off, which compared to "broke the app", seems better.

I've also added a rescue to the method so hopefully we don't run into more surprises here.

(Note that while we could've kept calling Bundler.bin_path, wrapping it with the rescue, this would still produce the side-effect of creating the folder and it seems weird to me to end up in this situation of "turning on the profiler causes bin/ to be created". This is why I chose to reimplement the behavior, minus folder creation)

How to test the change?

I've updated the test coverage.

Furthermore, the repro mentioned in #5137 also works to show it's fixed:

$ rm -rf bin/
$ chmod -w .
$ bundle exec rake compile && DD_PROFILING_ENABLED=true bundle exec ruby -rdatadog/profiling/preload -e "puts 'hello'"

**What does this PR do?**

This PR fixes a regression introduced in #4999: In that PR we added a
call to `Bundler.bin_path` but did not realize that bundler not only
returns the path **BUT CRUCIALLY** it makes sure the path exists
by going as far as trying to create it if it doesn't.

If the directory does not exist, and the application directory is
read-only (or the app does not have enough permissions), the
application will fail with:

> There was an error while trying to write to (directory). It is likely
> that you need to grant write permissions for that path.
> (Bundler::PermissionError)

Fixes #5137

**Motivation:**

Fix a regression introduced in #4999 that shipped in v2.23.0.

**Additional Notes:**

The bundler's `bin_path` method has had a similar
behavior/implementation for 15+ years:

* master -> https://github.com/ruby/rubygems/blob/570c3419c7f111d8665710f4e2cb15ca878e606d/bundler/lib/bundler.rb#L119-L126
* Jul 10, 2010 -> ruby/rubygems@f799489

So we should be fine in replicating its behavior + having a
test that checks we're matching it.

Worst case, we get `CodeProvenance` slightly off, which
compared to "broke the app", seems better.

I've also added a `rescue` to the method so hopefully
we don't run into more surprises here.

(Note that while we could've kept calling `Bundler.bin_path`,
wrapping it with the `rescue`, this would still produce the
side-effect of creating the folder and it seems weird to
me to end up in this situation of "turning on the profiler
causes bin/ to be created". This is why I chose to reimplement
the behavior, minus folder creation)

**How to test the change?**

I've updated the test coverage.

Furthermore, the repro mentioned in #5137 also works to
show it's fixed:

```bash
$ rm -rf bin/
$ chmod -w .
$ bundle exec rake compile && DD_PROFILING_ENABLED=true bundle exec ruby -rdatadog/profiling/preload -e "puts 'hello'"
```
@ivoanjo ivoanjo requested review from a team as code owners December 15, 2025 09:52
@github-actions github-actions bot added the profiling Involves Datadog profiling label Dec 15, 2025
@datadog-official
Copy link

datadog-official bot commented Dec 15, 2025

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage
Patch Coverage: 95.83%
Overall Coverage: 95.24% (-0.00%)

View detailed report

This comment will be updated automatically if new data arrives.
* Fix with Cursor requires Datadog plugin ≥v2.17.0
🔗 Commit SHA: bbdbf93 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@pr-commenter
Copy link

pr-commenter bot commented Dec 15, 2025

Benchmarks

Benchmark execution time: 2025-12-15 14:27:47

Comparing candidate commit bbdbf93 in PR branch ivoanjo/prof-13273-fix-bin-path-issue with baseline commit 1c94fa2 in branch master.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 43 metrics, 2 unstable metrics.

scenario:error - error tracking, with_error=true - third_party only

  • 🟩 throughput [+546.775op/s; +596.664op/s] or [+5.113%; +5.579%]

@p-datadog
Copy link
Member

Reported upstream: ruby/rubygems#9197

@ivoanjo ivoanjo merged commit 8da3cf0 into master Dec 16, 2025
553 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/prof-13273-fix-bin-path-issue branch December 16, 2025 09:00
@github-actions github-actions bot added this to the 2.24.0 milestone Dec 16, 2025
@Strech Strech mentioned this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Involves Datadog profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][PROF-13273] Regression - Profiler code provenance in 2.23.0 triggers Bundler::PermissionError for apps in read-only folder with no bin/

3 participants