Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 551563

Summary: Disable caching when a SQL error exists
Product: Community Reporter: Denis Roy <denis.roy>
Component: WebsiteAssignee: Christopher Guindon <chris.guindon>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: chris.guindon
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/150895
https://git.eclipse.org/c/www.eclipse.org/eclipse.org-common.git/commit/?id=b885a69628cb63222602db069aa8a695f0c033ce
Whiteboard:
Attachments:
Description Flags
Error screenshot none

Description Denis Roy CLA 2019-09-27 09:17:57 EDT
Created attachment 280070 [details]
Error screenshot

If a SQL error occurs, I believe there are no no-cache headers, so the error page gets cached by our nginx device for longer than it needs to be.

Can we set no-cache headers if there's an SQL error?
Comment 1 Christopher Guindon CLA 2019-09-27 09:43:50 EDT
As discussed on Slask with Denis, we should return a status 500 on these error page to avoid caching from nginx.
Comment 2 Christopher Guindon CLA 2019-10-10 12:27:58 EDT
I will submit a patch to address errors triggered by $App->mysqlErrorCheck();
Comment 3 Eclipse Genie CLA 2019-10-10 12:35:18 EDT
New Gerrit change created: https://git.eclipse.org/r/150895
Comment 4 Denis Roy CLA 2019-10-10 13:10:42 EDT
I don't think this will work, as there is output content prior to setting the header. As the output is buffered by php, we may have a chance.

I suggest this prior to your header() call:

$stuff = ob_get_contents();
ob_end_clean();
header('HTTP/1.1 500 Internal Server Error');
echo $stuff; # Send the actual error to the screen. Do we want to do this?
exit();
Comment 5 Denis Roy CLA 2019-10-10 14:26:24 EDT
I submitted an edit.
https://git.eclipse.org/r/#/c/150895/
Comment 6 Christopher Guindon CLA 2019-10-10 17:48:24 EDT
(In reply to Denis Roy from comment #4)
> I don't think this will work, as there is output content prior to setting
> the header. As the output is buffered by php, we may have a chance.
> 
> I suggest this prior to your header() call:
> 
> $stuff = ob_get_contents();
> ob_end_clean();
> header('HTTP/1.1 500 Internal Server Error');
> echo $stuff; # Send the actual error to the screen. Do we want to do this?
> exit();

What  will not work? The status code won't be a 500 or the mysql error won't be printed on the page?

The php script below should return a status 500 with the content "before and after!":

<?php
echo 'before ';
ob_start();

echo 'and after!';
header('HTTP/1.1 500 Internal Server Error');
exit;

It's important to note that both solution won't work if the server already sent the headers and we can't assume that output buffering is enabled since the error could occur prior to turning it on. 

Also, headers are sent even if output buffering is enabled:
https://www.php.net/manual/en/function.ob-start.php
Comment 7 Christopher Guindon CLA 2019-10-10 17:58:24 EDT
I did some testing on my end and I am getting the same result with both solution.
Comment 8 Denis Roy CLA 2019-10-11 09:52:40 EDT
(In reply to Christopher Guindon from comment #7)
> I did some testing on my end and I am getting the same result with both
> solution.

My 2c: let's keep my solution, since it handles the ob explicitly. But I don't have strong opinions about it.
Comment 9 Christopher Guindon CLA 2019-10-11 10:17:50 EDT
(In reply to Denis Roy from comment #8)
> (In reply to Christopher Guindon from comment #7)
> > I did some testing on my end and I am getting the same result with both
> > solution.
> 
> My 2c: let's keep my solution, since it handles the ob explicitly. But I
> don't have strong opinions about it.

+1 I don't have strong opinion about it as-well since both seems to behave the same!

Commit has been changed.
Comment 11 Christopher Guindon CLA 2019-10-11 10:18:33 EDT
*Commit has been merged.