Fix thread safety issue in async fs functions file paths (#3964)

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-08-03 20:09:05 -07:00
committed by GitHub
parent 717f0a2f42
commit 9beccc3305
6 changed files with 91 additions and 9 deletions

View File

@@ -829,6 +829,13 @@ pub const String = extern struct {
return bun.strings.eqlLong(this.byteSlice(), value, true);
}
extern fn BunString__toThreadSafe(this: *String) void;
pub fn toThreadSafe(this: *String) void {
if (this.tag == .WTFStringImpl) {
BunString__toThreadSafe(this);
}
}
pub fn eql(this: String, other: String) bool {
return this.toZigString().eql(other.toZigString());
}
@@ -838,6 +845,23 @@ pub const SliceWithUnderlyingString = struct {
utf8: ZigString.Slice,
underlying: String,
pub fn toThreadSafe(this: *SliceWithUnderlyingString) void {
std.debug.assert(this.underlying.tag == .WTFStringImpl);
var orig = this.underlying.value.WTFStringImpl;
this.underlying.toThreadSafe();
if (this.underlying.value.WTFStringImpl != orig) {
orig.deref();
if (this.utf8.allocator.get()) |allocator| {
if (String.isWTFAllocator(allocator)) {
this.utf8.deinit();
this.utf8 = this.underlying.toUTF8(bun.default_allocator);
}
}
}
}
pub fn deinit(this: SliceWithUnderlyingString) void {
this.utf8.deinit();
this.underlying.deref();