Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DebugBundle] Fix dump/die doesn't work with server dumper #27397

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

Closed
wants to merge 2 commits into from
Closed

[DebugBundle] Fix dump/die doesn't work with server dumper #27397

wants to merge 2 commits into from

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented May 28, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

This is an attempt to fully respect the promise made by the server dumper feature, i.e: dump should act exactly the same when the ServerDumper is wired (debug.dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%") but the dump server is not up (server:dump not running).

Currently, when using the full stack and debug bundle, the promise is broken, as someone using dd or dump + die would not see expected dumps in the output for web requests. This is explained by the wrapped dumper (the one used by ServerDumper when failing at contacting the server) being the var_dumper.cli_dumper, so it outputs on php://stdout instead (which is fine for cli usages).

To reproduce

  • composer create-project "symfony/website-skeleton:^4.1@dev" no-dd-output
  • Add a controller and dd inside
  • Start the webserver and access the controller => get a blank page, dumps are written to the webserver output.

What this solution is worth

It works, but is far from ideal. It reproduces the DumpDataCollector behavior (code is entirely borrowed from here) in a dedicated internal dumper used as the fallback when we failed at contacting the server. Also, it misses the file & line nb usually added by the collector in the output (or would also need duplicating this logic). => Now added
Ideally, the ServerDumper's wrapped dumper should be DumpDataCollector but it's not easily achievable as those are already quite intricated/tangled with each other in the way they are wired together. I failed to find a proper solution so far.
=> See #27614 (comment) last paragraph for a strategy extracting, deprecating & removing some code from DumpDataCollector, limiting it to its responsibility of collecting dumps to be shown on toolbar/profiler, in favor of the DebugDumper (attempt in progress).

Reverting #26675 makes things work, but the fix is legit and it would only rely on undesired behavior while still using the cli dumper as the wrapped dumper (thus leading to duplicates at the end of the process when one is calling a controller, e.g when executing a test suite).

@lyrixx
Copy link
Member

lyrixx commented Jun 12, 2018

I did not read the code, but:

  1. I confirm there is a bug
  2. I confirm this patch fix the bug

public function dump(Data $data)
{
// only delay web requests
if (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true)) {
Copy link
Member

Choose a reason for hiding this comment

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

I would use if (\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg'), which can be resolved by OPCache at compile time

$response = $event->getResponse();
$request = $event->getRequest();

// In all conditions that remove the web debug toolbar, dumps must be written on the output.
Copy link
Member

Choose a reason for hiding this comment

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

why would this service check the debug toolbar being injected or no ? This class is not related to the data collector AFAICT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right it's not directly related to the data collector, but this whole patch aims to ensure the exact same behavior exists whether the server dumper is wired or not.
When not wired and the toolbar being injected, dumps are already rendered in the toolbar and considered not to be output twice by the collector.

@ogizanagi
Copy link
Contributor Author

ogizanagi commented Jun 20, 2018

After some discussion, closing in favor of #27614 with some compromises to avoid BC breaks.
Also, I won't explore more what has been started master...ogizanagi:4.2/refacto_dump_collector for now. Anyway will keep a trace if this can be re-considered in the future.

@ogizanagi ogizanagi closed this Jun 20, 2018
nicolas-grekas added a commit that referenced this pull request Jun 24, 2018
… of Dumper/ServerDumper (nicolas-grekas)

This PR was merged into the 4.1 branch.

Discussion
----------

[VarDumper] Fix dumping by splitting Server/Connection out of Dumper/ServerDumper

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27622
| License       | MIT
| Doc PR        | -

Right now, the `dump()` function is broken on 4.1 as soon as one sets up a `dump_destination` for the dump server (as done by default by our Flex recipe). #27397 describes the issue and proposes a tentative fix. Yet, I think the issue is deeper and exists at the design level. Writting to the server should not happen in a `DumperInterface`, that's not its semantics. Instead, I propose a `Connection` object that will allow `DumpDataCollector` to have all the info it requires to do everything on its own.

My bad for not spotting this at the review stage.

Commits
-------

1435d67 [VarDumper] Fix dumping by splitting Server/Connection out of Dumper/ServerDumper
@ogizanagi ogizanagi deleted the fix/runtime_server_dumper_wrapped_dumper branch October 31, 2018 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.