Skip to content

Commit 3177212

Browse files
committed
[GR-14882] Fix race condition with interpolate-once regular expressions.
PullRequest: truffleruby/765
2 parents 0ec63c6 + abf40b9 commit 3177212

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Bug fixes:
77
encoding and has non-ASCII characters.
88
* Fixed `puts` for strings with non-ASCII-compatible encodings.
99
* `rb_protect` now returns `Qnil` when an error occurs.
10+
* Fixed a race condition when using the interpolate-once (`/o`) modifier in
11+
regular expressions.
1012

1113
New features:
1214

src/main/java/org/truffleruby/language/control/OnceNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public Object execute(VirtualFrame frame) {
3535
if (value == null) {
3636
CompilerDirectives.transferToInterpreterAndInvalidate();
3737
synchronized (this) {
38-
if (cachedValue == null) {
38+
// Read `cachedValue` again to check if the value was updated by another thread while this thread
39+
// was waiting on the lock. If it's still null, this thread is the first one to get the lock and
40+
// must update the cache.
41+
value = cachedValue;
42+
if (value == null) {
3943
value = cachedValue = child.execute(frame);
4044
assert value != null;
4145
}

0 commit comments

Comments
 (0)