-
Notifications
You must be signed in to change notification settings - Fork 166
feat(tracer): add configuration for connection mode #3573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Leiyks
wants to merge
6
commits into
master
Choose a base branch
from
leiyks/sidecar-threaded-fallback
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63b5353
feat(tracer): add configuration for connection mode
Leiyks 4ee7f1c
feat(tracer): add sidecar thread listener module
Leiyks 38890f9
feat(tracer): implement threaded connection fallback
Leiyks 37ec8f2
fix: compilation error
Leiyks cda73e8
fix(tracer): remove debug logs
Leiyks fc9fcbf
feat(tracer): add connection mode and function thread mode tests
Leiyks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1529,6 +1529,7 @@ static PHP_MINIT_FUNCTION(ddtrace) { | |
| #endif | ||
| ddshared_minit(); | ||
| ddtrace_autoload_minit(); | ||
| ddtrace_sidecar_minit(); | ||
|
|
||
| dd_register_span_data_ce(); | ||
| dd_register_fatal_error_ce(); | ||
|
|
@@ -1585,7 +1586,9 @@ static PHP_MSHUTDOWN_FUNCTION(ddtrace) { | |
| #ifndef _WIN32 | ||
| ddtrace_signals_mshutdown(); | ||
|
|
||
| if (!get_global_DD_TRACE_SIDECAR_TRACE_SENDER()) { | ||
| // For CLI SAPI, background sender is already shut down in RSHUTDOWN | ||
| // For non-CLI SAPIs, shut it down here in MSHUTDOWN | ||
| if (!get_global_DD_TRACE_SIDECAR_TRACE_SENDER() && strcmp(sapi_module.name, "cli") != 0) { | ||
| ddtrace_coms_mshutdown(); | ||
| if (ddtrace_coms_flush_shutdown_writer_synchronous()) { | ||
| ddtrace_coms_curl_shutdown(); | ||
|
|
@@ -1612,7 +1615,11 @@ static PHP_MSHUTDOWN_FUNCTION(ddtrace) { | |
|
|
||
| ddtrace_user_req_shutdown(); | ||
|
|
||
| ddtrace_sidecar_shutdown(); | ||
| // Only shutdown sidecar in MSHUTDOWN for non-CLI SAPIs | ||
| // CLI SAPI shuts down in RSHUTDOWN to allow thread joins before ASAN checks | ||
| if (strcmp(sapi_module.name, "cli") != 0) { | ||
| ddtrace_sidecar_shutdown(); | ||
| } | ||
|
|
||
| ddtrace_live_debugger_mshutdown(); | ||
|
|
||
|
|
@@ -2632,6 +2639,21 @@ void dd_internal_handle_fork(void) { | |
| ddtrace_coms_curl_shutdown(); | ||
| ddtrace_coms_clean_background_sender_after_fork(); | ||
| } | ||
|
|
||
| // Handle thread mode after fork | ||
| int32_t current_pid = (int32_t)getpid(); | ||
| bool is_child_process = (ddtrace_sidecar_master_pid != 0 && | ||
| current_pid != ddtrace_sidecar_master_pid); | ||
|
|
||
| if (is_child_process && ddtrace_sidecar_active_mode == DD_SIDECAR_CONNECTION_THREAD) { | ||
| // Clear inherited master listener state (child doesn't own it) | ||
| ddtrace_ffi_try("Failed clearing inherited listener state", | ||
| ddog_sidecar_clear_inherited_listener()); | ||
|
|
||
| // Don't try to reconnect in thread mode after fork | ||
| // Let sidecar stay unavailable | ||
| LOG(WARN, "Child process after fork with thread mode: sidecar unavailable"); | ||
|
Comment on lines
+2653
to
+2655
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm, no? Just connect to the parents process socket? At least attempt to. |
||
| } | ||
| #endif | ||
| if (DDTRACE_G(agent_config_reader)) { | ||
| ddog_agent_remote_config_reader_drop(DDTRACE_G(agent_config_reader)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,15 @@ static void dd_prefork() { | |
|
|
||
| static void dd_handle_fork(zval *return_value) { | ||
| if (Z_LVAL_P(return_value) == 0) { | ||
| // CHILD PROCESS | ||
|
|
||
| // Warn if thread mode is active | ||
| if (ddtrace_sidecar_active_mode == DD_SIDECAR_CONNECTION_THREAD) { | ||
| LOG(WARN, "pcntl_fork() detected with thread-based sidecar connection. " | ||
| "Thread mode is incompatible with fork and may cause instability. " | ||
| "Consider using subprocess mode (DD_TRACE_SIDECAR_CONNECTION_MODE=subprocess)."); | ||
|
Comment on lines
+44
to
+46
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is? Why? |
||
| } | ||
|
|
||
| dd_internal_handle_fork(); | ||
| } else { | ||
| #if JOIN_BGS_BEFORE_FORK | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does ASAN influence this? ASAN is supposed to run after MSHUTDOWN as well?
I suspect that is related to the timings and the fact that the libdatadog part doesn't properly handle shutdown currently.
And this should in fact always shutdown the sidecar in MSHUTDOWN.