Skip to content

Commit

Permalink
Fix various autoload race conditions. (ruby#5898)
Browse files Browse the repository at this point in the history
* Add RUBY_VM_CRITICAL_SECTION for detecting unexpected context switch.

* Prevent race between GC mark and autoload setup.

* Protect race on autoload state.

* Avoid potential race condition when allocating `autoload_featuremap`.

* Add NEWS entry for autoload fixes.
  • Loading branch information
ioquatix committed May 15, 2022
1 parent 48002ff commit 32de609
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 77 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ The following deprecated APIs are removed.

## Implementation improvements

* Fixed several race conditions in `Kernel#autoload`. [[Bug #18782]]

## JIT

### MJIT
Expand Down Expand Up @@ -253,3 +255,4 @@ The following deprecated APIs are removed.
[Feature #18598]: https://bugs.ruby-lang.org/issues/18598
[Bug #18625]: https://bugs.ruby-lang.org/issues/18625
[Bug #18633]: https://bugs.ruby-lang.org/issues/18633
[Bug #18782]: https://bugs.ruby-lang.org/issues/18782
4 changes: 4 additions & 0 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,10 @@ static inline int
blocking_region_begin(rb_thread_t *th, struct rb_blocking_region_buffer *region,
rb_unblock_function_t *ubf, void *arg, int fail_if_interrupted)
{
#ifdef RUBY_VM_CRITICAL_SECTION
VM_ASSERT(rb_vm_critical_section_entered == 0);
#endif

region->prev_status = th->status;
if (unblock_function_set(th, ubf, arg, fail_if_interrupted)) {
th->blocking_region_buffer = region;
Expand Down
Loading

0 comments on commit 32de609

Please sign in to comment.