Skip to content

[WebProfilerBundle ] Fixed an edge case on WDT loading #10773

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

Conversation

tucksaun
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #6824 ?
License MIT
Doc PR none

In some case you can notice the WDT just disappears.
By tracking it down, I noticed that the XHR call returns an empty response with 200 as status code, but if you go directly on the _wdt/my_token URL it works correctly.
What's happening is that when you have a slow listener on kernel.terminate (for example the SwiftMailer one with a slow connection), you response (and therefore the WDT javascript) is sent and processed by the browser, the XHR call is done, but the Profiler storage didn't happened yet so no profiling data is available and the ProfilerController just sends an empty response with 200 as status code.

Here we change to instead send a specific status code, and treat it in javascript by retrying several times before failing.

The question are:

  • Is 204 the most appropriate response code?
  • Are 500 ms and 5 max retries good values?

@stof
Copy link
Member

stof commented Apr 24, 2014

There is an issue here: you are handling retriesCount as a global variable. This is broken. Each Ajax loading through Sfjs.request (or Sfjs.load) should have its own retrying count. Otherwise, it will simply not work when several ajax calls are done.

And for other elements loaded through Ajax, retyring may not always make sense. IMO, the maxTry should be an argument passed to request() (and you pass maxTry - 1 when retrying), and the WDT toolbar loading should be passing the argument.
Retrying the loading of query explanations in the Doctrine panel does not make sense for instance.

@@ -239,7 +239,7 @@ public function toolbarAction(Request $request, $token)
$this->profiler->disable();

if (!$profile = $this->profiler->loadProfile($token)) {
return new Response('', 200, array('Content-Type' => 'text/html'));
return new Response('', 204, array('Content-Type' => 'text/html'));
Copy link
Member

Choose a reason for hiding this comment

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

why 204 ? a 400 is a better status code IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

404 then, not 400. but indeed, 404 would be better if the profile does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is exactly why I asked the question if it was accurate :)
However I didn't take the initiative of sending a 404 because it was a 200 before and thought there was a reason to that

But yeah I also prefer 404

@tucksaun
Copy link
Contributor Author

@stof yeah you're right I will update it, but I did not know that something else were using the Sfjs.request or Sfjs.load, thanks for the tips

@tucksaun
Copy link
Contributor Author

@stof updated

@fabpot
Copy link
Member

fabpot commented Apr 25, 2014

Thank you @tucksaun.

fabpot added a commit that referenced this pull request Apr 25, 2014
…cksaun)

This PR was squashed before being merged into the 2.3 branch (closes #10773).

Discussion
----------

[WebProfilerBundle ] Fixed an edge case on WDT loading

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

In some case you can notice the WDT just disappears.
By tracking it down, I noticed that the XHR call returns an empty response with 200 as status code, but if you go directly on the _wdt/my_token URL it works correctly.
What's happening is that when you have a slow listener on `kernel.terminate` (for example the SwiftMailer one with a slow connection), you response (and therefore the WDT javascript) is sent and processed by the browser, the XHR call is done, but the Profiler storage didn't happened yet so no profiling data is available and the `ProfilerController` just sends an empty response with 200 as status code.

Here we change to instead send a specific status code, and treat it in javascript by retrying several times before failing.

The question are:
* Is 204 the most appropriate response code?
* Are 500 ms and 5 max retries good values?

Commits
-------

9d885ed [WebProfilerBundle ] Fixed an edge case on WDT loading
@fabpot fabpot closed this Apr 25, 2014
@tucksaun tucksaun deleted the fix-no-wdt-on-long-kernel-terminate branch April 25, 2014 12:49
tucksaun added a commit to tucksaun/symfony that referenced this pull request Apr 30, 2014
tucksaun added a commit to tucksaun/symfony that referenced this pull request Apr 30, 2014
tucksaun added a commit to tucksaun/symfony that referenced this pull request Apr 30, 2014
fabpot added a commit that referenced this pull request Apr 30, 2014
…ty token (tucksaun)

This PR was merged into the 2.3 branch.

Discussion
----------

[WebProfilerBundle] Fixed profiler seach/homepage with empty token

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

Commits
-------

16dd0e5 [WebProfilerBundle] added test case for #10773
5b91e70 [WebProfilerBundle] fixed profiler homepage, fixed #10806
7b425d2 [WebProfilerBundle] Added test case for #10806
fabpot added a commit that referenced this pull request May 12, 2014
* 2.3:
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for #10773
  [WebProfilerBundle] fixed profiler homepage, fixed #10806
  [WebProfilerBundle] Added test case for #10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue #5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
fabpot added a commit that referenced this pull request May 12, 2014
* 2.4:
  Lower mbstring dependency
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Security] fixed wrong PHPDoc of the TokenGeneratorInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for #10773
  [WebProfilerBundle] fixed profiler homepage, fixed #10806
  [WebProfilerBundle] Added test case for #10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue #5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
	src/Symfony/Component/Console/Application.php
@tucksaun tucksaun mentioned this pull request May 29, 2014
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.3:
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for symfony#10773
  [WebProfilerBundle] fixed profiler homepage, fixed symfony#10806
  [WebProfilerBundle] Added test case for symfony#10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue symfony#5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.4:
  Lower mbstring dependency
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Security] fixed wrong PHPDoc of the TokenGeneratorInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for symfony#10773
  [WebProfilerBundle] fixed profiler homepage, fixed symfony#10806
  [WebProfilerBundle] Added test case for symfony#10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue symfony#5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
	src/Symfony/Component/Console/Application.php
jderusse pushed a commit to jderusse/symfony that referenced this pull request Dec 15, 2020
* 2.3:
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for symfony#10773
  [WebProfilerBundle] fixed profiler homepage, fixed symfony#10806
  [WebProfilerBundle] Added test case for symfony#10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue symfony#5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
jderusse pushed a commit to jderusse/symfony that referenced this pull request Dec 15, 2020
* 2.4:
  Lower mbstring dependency
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Security] fixed wrong PHPDoc of the TokenGeneratorInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for symfony#10773
  [WebProfilerBundle] fixed profiler homepage, fixed symfony#10806
  [WebProfilerBundle] Added test case for symfony#10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue symfony#5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
	src/Symfony/Component/Console/Application.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants