Commit e1b4f56
authored
fix(ruby): keep OpenTelemetry FFI config reference (#198)
* fix(ruby): keep OpenTelemetry FFI config buffers alive across init
build_config stored only the raw addresses of the nested traces/metrics
FFI struct wrappers and their endpoint string buffers into the config
struct, then let those wrapper objects go out of scope. The endpoint
MemoryPointers are retained by the wrapper struct instances, not by the
config struct (which holds only their backing addresses), so GC between
build_config returning and Bindings.init_open_telemetry running could
free the endpoint buffers -- leaving config->traces/metrics->endpoint
dangling when the native layer reads them (use-after-free).
build_config now returns [config_struct, keep_alive] where keep_alive
pins the nested struct wrappers and endpoint buffers; init stashes it in
@config_refs for the process lifetime (init is one-time), guaranteeing
the memory outlives the native call. Mirrors the buffer-pinning pattern
in build_command_args.
Related to #179.
Signed-off-by: Alex Le <alex.le@improving.com>
* refactor(ruby): release OTel config buffers after init instead of pinning for process lifetime
The native init_open_telemetry copies the endpoint strings synchronously
(CStr::from_ptr(...).to_string()) and retains no pointers, so the config
buffers only need to outlive the single FFI call. Hold keep_alive as a
local across the call and clear it afterwards rather than stashing it in
a process-lifetime @config_refs ivar. Also documents build_config's
two-element return and its buffer-pinning contract.
Related to #179.
Signed-off-by: Alex Le <alex.le@improving.com>
* docs: updated comments
Signed-off-by: Alex Le <alex.le@improving.com>
---------
Signed-off-by: Alex Le <alex.le@improving.com>1 parent 7121a4c commit e1b4f56
1 file changed
Lines changed: 26 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
102 | 104 | | |
103 | | - | |
104 | 105 | | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
223 | 225 | | |
224 | 226 | | |
225 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
226 | 240 | | |
227 | 241 | | |
228 | 242 | | |
| 243 | + | |
| 244 | + | |
229 | 245 | | |
230 | 246 | | |
231 | 247 | | |
232 | 248 | | |
233 | 249 | | |
234 | | - | |
| 250 | + | |
| 251 | + | |
235 | 252 | | |
236 | 253 | | |
237 | 254 | | |
| |||
242 | 259 | | |
243 | 260 | | |
244 | 261 | | |
| 262 | + | |
| 263 | + | |
245 | 264 | | |
246 | 265 | | |
247 | 266 | | |
| |||
251 | 270 | | |
252 | 271 | | |
253 | 272 | | |
254 | | - | |
| 273 | + | |
| 274 | + | |
255 | 275 | | |
| 276 | + | |
256 | 277 | | |
257 | 278 | | |
258 | 279 | | |
| |||
266 | 287 | | |
267 | 288 | | |
268 | 289 | | |
269 | | - | |
| 290 | + | |
270 | 291 | | |
271 | 292 | | |
272 | 293 | | |
| |||
0 commit comments