Commit 0b00c9c
authored
refactor(profiling): split upload function (#1733)
## What does this PR do?
This PR splits the Exporter creation process into two steps (two functions to call):
1. Create the Tokio runtime with `init_runtime`
2. Upload the Profile with `send_blocking` (`send_blocking` calls `init_runtime` if it hasn't been initialised from the outside)
This fixes a TSan-detected race condition where we try to cancel the Upload request (using the Cancellation Token) at the same time the runtime is being initialised.
Example runtime Profiler fix PR: DataDog/dd-trace-py#16467
The PR also updates the existing `exporter.cpp` example to use the new function (tested with `cargo ffi-test --filter exporter`).
## Open questions
Currently, the PR maintains compatibility with existing usages -- not explicitly calling `init_runtime` will make `send_blocking` call it when it needs it. However, this is risky (for the reasons that made us make this PR in the first place).
* Should we prevent people from doing this? _Doing so will break compatibility with current usages._
* ... Or should we instead keep the race? _Doing so will guarantee backwards compatibility but also not force usages to be fixed._
--- We ended up going for the second, keeping the race so that we don't have a breaking API change.
Co-authored-by: thomas.kowalski <thomas.kowalski@datadoghq.com>1 parent 04c735c commit 0b00c9c
3 files changed
Lines changed: 63 additions & 7 deletions
File tree
- examples/ffi
- libdd-profiling-ffi/src
- libdd-profiling/src/exporter
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
225 | 252 | | |
226 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
227 | 257 | | |
228 | 258 | | |
229 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
164 | 184 | | |
165 | 185 | | |
166 | 186 | | |
| |||
172 | 192 | | |
173 | 193 | | |
174 | 194 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 195 | + | |
182 | 196 | | |
183 | 197 | | |
184 | 198 | | |
| |||
0 commit comments