Skip to content

Commit b29163a

Browse files
committed
More lifetime documentation.
1 parent 7060a38 commit b29163a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

libs/server-sdk/src/hooks/hook_executor.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ namespace launchdarkly::server_side::hooks {
1717
*
1818
* Handles exceptions/errors from hooks and logs them without affecting
1919
* the evaluation operation.
20+
*
21+
* THREADING AND LIFETIME GUARANTEES:
22+
* - All hook callbacks are executed SYNCHRONOUSLY in the same thread as the
23+
* caller of the SDK method (e.g., BoolVariation, Track).
24+
* - Hook callbacks complete before control returns to the caller.
25+
* - Context objects (EvaluationSeriesContext, TrackSeriesContext) passed to
26+
* hooks are stack-allocated and remain valid for the entire duration of
27+
* the callback.
28+
* - This synchronous execution model is CRITICAL for the C bindings, which
29+
* return pointers to internal data that are only valid during the callback.
30+
* Asynchronous execution would create dangling pointers.
31+
* - Hook implementations MUST NOT store references, pointers, or string_views
32+
* from context objects beyond the immediate callback execution.
33+
*
34+
* IMPLEMENTATION REQUIREMENTS:
35+
* - Do NOT introduce async hook execution without redesigning the C bindings.
36+
* - Do NOT move hook execution to background threads.
37+
* - If async hooks are needed in the future, the C bindings must be changed
38+
* to return heap-allocated copies instead of pointers to stack data.
2039
*/
2140
class EvaluationSeriesExecutor {
2241
public:
@@ -59,6 +78,14 @@ class EvaluationSeriesExecutor {
5978

6079
/**
6180
* Utility for executing track hooks.
81+
*
82+
* THREADING AND LIFETIME GUARANTEES:
83+
* - Executes all hooks SYNCHRONOUSLY in the caller's thread.
84+
* - The TrackSeriesContext parameter must remain valid for the entire
85+
* execution (typically stack-allocated by the caller).
86+
* - Returns only after all hook callbacks have completed.
87+
* - This synchronous model is REQUIRED for C binding safety - the C bindings
88+
* return pointers to data owned by the context parameter.
6289
*/
6390
void ExecuteAfterTrack(std::vector<std::shared_ptr<Hook>> const& hooks,
6491
TrackSeriesContext const& context,

0 commit comments

Comments
 (0)