Commit 98620f5
authored
### Rationale for this change
Before this change it was possible for two threads calling `field()` with the same index at the same time to cause a race on the stored entry in `boxed_fields_`. I.e. if a second thread goes into the path that calls `MakeArray` before the first thread stored its own new array, the second thread would also write to the same `shared_ptr` and invalidate the `shared_ptr` from the first thread, thereby also invalidating the returned reference.
### What changes are included in this PR?
This PR changes the return type of `StructArray::field()` from `shared_ptr<Array>&` to `shared_ptr<Array>` giving the caller co-ownership of the data and safeguarding against any potential concurrent writes to the underlying `boxed_fields_` vector.
It also changes the body to use the CAS pattern to avoid multiple concurrent writes to the same address.
### Are these changes tested?
I don't know how to write a deterministic test that triggers the issue before the fix. Even a non-deterministic test needs to run with address sanitizer or valgrind or something similar.
I can however confirm that this change fixes an issue that I've been debugging in https://github.com/tenzir/tenzir.
### Are there any user-facing changes?
While changing `StructArray::field()` to return by value is an API change, I believe this should be compatible with regular uses of that function.
* GitHub Issue: #48134
Authored-by: Tobias Mayer <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
1 parent 83a5a61 commit 98620f5
2 files changed
+18
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1076 | 1076 | | |
1077 | 1077 | | |
1078 | 1078 | | |
1079 | | - | |
| 1079 | + | |
1080 | 1080 | | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
| 1081 | + | |
| 1082 | + | |
1091 | 1083 | | |
1092 | | - | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
1093 | 1098 | | |
1094 | 1099 | | |
1095 | 1100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
692 | 692 | | |
693 | 693 | | |
694 | 694 | | |
695 | | - | |
| 695 | + | |
696 | 696 | | |
697 | 697 | | |
698 | 698 | | |
| |||
0 commit comments