Project

General

Profile

Actions

Bug #54323

closed

$GLOBALS['TYPO3_DB']->isConnected() doesn't work when MySQL server has gone away

Added by Bill Dagou almost 11 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
Start date:
2013-12-11
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.1
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Dear TYPO3 Team,

Thank you for your great work on TYPO3, it's really a powerful CMS I could tell.

When I was working on my own extension, I found a DB problem with CLI, not sure whether it would happen in web or not.

The situation is, I was using both cUrl and sleep in my code, and I would get "MySQL server has gone away" error while $GLOBALS['TYPO3_DB']->isConnected() could not detect it. And the code logic is as follow.

------------------------------- Code logic start -----------------------------------
// cUrl a captcha image and save it to the server
..........

do {
sleep(15); // Set 15 seconds delay for manually enter the captcha code in captcha.txt file.

// Load the content of captcha.txt and set it to $captcha
.........
} while (!$captcha);

// cUrl the login page with $captcha
.........

// Get the page content and insert it into the database
$GLOBALS['TYPO3']->exec_INSERTquery('table', $insertArray);
------------------------------- Code logic end -----------------------------------

I think the problem is $GLOBALS['TYPO3_DB']->isConnected() is returning $this->isConnected rather than checking the real connection. And what I do now is $GLOBALS['TYPO3_DB']->__sleep() before the db operation.

BTW, if I choose the wrong project, please help to correct it. There are a lot in the list, and I don't know which one to choose :)

Cheers,
Bill

Actions #1

Updated by Markus Klein almost 11 years ago

  • Status changed from New to Needs Feedback

I guess that is independent of CLI or WEB, but what is your suggestion to detect in isConnected() if the database is still alive?

Actions #2

Updated by Bill Dagou almost 11 years ago

According to php manual, I think $this->link->ping() should be working, see my change below

public function isConnected() {
return $this->isConnected ? $this->link->ping() : FALSE; // or maybe is_object($this->link) ? $this->link->ping() : FALSE; But I think $this->isConnected should be better.
}

But in this case, I'm afraid

if ($this->isConnected) {
...
}

should be changed to accordingly

if ($this->isConnected()) {
...
}
Actions #3

Updated by Bill Dagou almost 11 years ago

And

if (!$this->isConnected) {
...
}

to

if (!$this->isConnected()) {
...
}

Actions #4

Updated by Markus Klein almost 11 years ago

  • Category set to Database API (Doctrine DBAL)
  • Status changed from Needs Feedback to Accepted
  • Target version set to next-patchlevel
Actions #5

Updated by Markus Klein almost 11 years ago

I would not replace the checks to isConnected with the function call. This would cause a performance penalty because ping() would be executed on every mysqli request.
It should suffice check with ping() when somebody explicitly wants to verify that the connection is still alive.

Actions #6

Updated by Gerrit Code Review almost 11 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/26447

Actions #7

Updated by Stephan Großberndt almost 11 years ago

Great news you found the cause! I had this issue in 4.5 and 4.7, but never found out what was the problem. Any chance of a backport of this to 4.5 / 4.7?

Actions #8

Updated by Markus Klein almost 11 years ago

I added the RMs for these versions as watchers. They will have to decide whether this will be backported or not.

I'm not even sure (codewise) if this is easy to backport.

Actions #9

Updated by Gerrit Code Review almost 11 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/26447

Actions #10

Updated by Bill Dagou almost 11 years ago

Dear Markus,

Great, the $GLOBALS['TYPO3_DB']->isConnected() works.

One problem is I need to check $GLOBALS['TYPO3_DB']->isConnected() before $GLOBALS['TYPO3']->exec_INSERTquery(), but I think it's acceptable :)

BTW, researched during the period, the final reason is the setting in mysql, called wait_timeout. When the time between 2 queries is longer than wait_timeout, it will get "MySQL server has gone away". See http://dev.mysql.com/doc/refman/5.1/en/gone-away.html .

Thank you so much, and Merry Christmas!

Cheers,
Bill

Actions #11

Updated by Markus Klein almost 11 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #12

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF