Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 726bff4

Browse files
committed
merge revision(s) c224ca4: [Backport #21172]
Fix a race condition with interned strings sweeping. [Bug #21172] This fixes a rare CI failure. The timeline of the race condition is: - A `"foo" oid=1` string is interned. - `"foo" oid=1` is no longer referenced and will be swept in the future. - Another `"foo" oid=2` string is interned. - `register_fstring` finds `"foo" oid=1`, but since it is about to be swept, removes it from `fstring_table` and insert `"foo" oid=2` instead. - `"foo" oid=1` is swept, since it has the `RSTRING_FSTR` flag, a `st_delete` is issued in `fstring_table` which removes `"foo" oid=2`. I don't know how to reproduce this bug consistently in a single test case.
1 parent 1d3c198 commit 726bff4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

string.c

+4
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t data, int exist
344344

345345
if (rb_objspace_garbage_object_p(str)) {
346346
arg->fstr = Qundef;
347+
// When RSTRING_FSTR strings are swept, they call `st_delete`.
348+
// To avoid a race condition if an equivalent string was inserted
349+
// we must remove the flag immediately.
350+
FL_UNSET_RAW(str, RSTRING_FSTR);
347351
return ST_DELETE;
348352
}
349353

version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 7
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 131
14+
#define RUBY_PATCHLEVEL 132
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)