Skip to content
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

fix: Don't handle fork in SWOOLE_BASE mode #2656

Merged
merged 2 commits into from
May 8, 2024
Merged

Conversation

PROFeNoM
Copy link
Contributor

@PROFeNoM PROFeNoM commented May 3, 2024

Description

Trying to set the callbacks before the instance is created is senseless: That's the bug.

--> This PR defers the dummy callbacks set to the posthook, so we have an instance.

What's more, swoole_fork_exec is not necessarily called. It only happens when the server isn't in "base" mode. The default behavior of swoole is to be in base mode, hence explaining why the tests were failing when the hook was done correctly (because no fork was happening - i.e., the pid was the same all along).

Why are the Laravel Octane tests working? Because it is, by default, using the SWOOLE_PROCESS mode.

--> With this PR, the fork is only handled when it happens - i.e., when is_base_mode evaluates to false.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@PROFeNoM PROFeNoM added the 🐛 bug Something isn't working label May 3, 2024
@PROFeNoM PROFeNoM self-assigned this May 3, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 79.20%. Comparing base (8388bc1) to head (154869e).
Report is 4 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2656      +/-   ##
============================================
+ Coverage     77.66%   79.20%   +1.54%     
- Complexity     2205     2207       +2     
============================================
  Files           225      199      -26     
  Lines         26019    22007    -4012     
  Branches        988        0     -988     
============================================
- Hits          20208    17431    -2777     
+ Misses         5285     4576     -709     
+ Partials        526        0     -526     
Flag Coverage Δ
appsec-extension ?
tracer-extension 78.47% <ø> (ø)
tracer-php 80.23% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../DDTrace/Integrations/Swoole/SwooleIntegration.php 0.00% <0.00%> (ø)

... and 26 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8388bc1...154869e. Read the comment docs.

@pr-commenter
Copy link

pr-commenter bot commented May 3, 2024

Benchmarks

Benchmark execution time: 2024-05-03 13:04:37

Comparing candidate commit 154869e in PR branch alex/fix/swoole-callback with baseline commit 8388bc1 in branch master.

Found 2 performance improvements and 0 performance regressions! Performance is the same for 176 metrics, 0 unstable metrics.

scenario:ContextPropagationBench/benchInject64Bit-opcache

  • 🟩 execution_time [-478.290ns; -165.710ns] or [-6.538%; -2.265%]

scenario:TraceSerializationBench/benchSerializeTrace-opcache

  • 🟩 mem_peak [-155.258KB; -51.287KB] or [-7.000%; -2.312%]

@PROFeNoM PROFeNoM changed the title fix: Callback after Swoole Server instance creation fix: Don't handle fork in SWOOLE_BASE mode May 3, 2024
@PROFeNoM PROFeNoM marked this pull request as ready for review May 3, 2024 12:49
@PROFeNoM PROFeNoM requested a review from a team as a code owner May 3, 2024 12:49
@PROFeNoM PROFeNoM requested a review from a team May 3, 2024 12:53
@bwoebi bwoebi merged commit f96c003 into master May 8, 2024
555 of 556 checks passed
@bwoebi bwoebi deleted the alex/fix/swoole-callback branch May 8, 2024 13:15
Copy link
Member

@labbati labbati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already a test failing to prove that this fix actually fixes the issue?

@@ -141,6 +149,7 @@ public function init(): int
\DDTrace\hook_method(
'Swoole\Http\Server',
'__construct',
null,
Copy link
Contributor Author

@PROFeNoM PROFeNoM May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@labbati Tests were failing when the hook was changed from a pre-hook to a post-hook. Traces were not received because we were supposing a fork would happen, while none did, hence introducing an issue with the background sender.

@bwoebi bwoebi added this to the 1.0.0 milestone May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working cat:integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants