Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove Dir.chdir for thread-safety#397

Open
lovro-bikic wants to merge 1 commit intorubysec:masterfrom
lovro-bikic:threadsafe-database-methods
Open

Remove Dir.chdir for thread-safety#397
lovro-bikic wants to merge 1 commit intorubysec:masterfrom
lovro-bikic:threadsafe-database-methods

Conversation

Copy link

lovro-bikic commented Oct 27, 2024

Currently, Bundler::Audit::Database#update!, #commit_id and #last_updated_at fail in multi-threaded environments (like background processing jobs) because they use Dir.chdir.

From Ruby docs on Dir.chdir:

In a multi-threaded program an error is raised if a thread attempts to open a chdir block while another thread has one open, or a call to chdir without a block occurs inside a block passed to chdir (even in the same thread).

This PR removes the need for Dir.chdir by using Open3.capture2 from the stdlib with the chdir option.

External behavior should stay the same: Dir.chdir raises an Errno::ENOENT error given an non-existent directory, and the same holds with the new implementation.

Fixes #156

lovro-bikic mentioned this pull request Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bundler audit is not thread safe

1 participant