evekb / evedev-kb

EVE Killboard
www.evekb.org
41 stars 22 forks source link

Error when running cron_esi.php #97

Open StinGer-ShoGuN opened 5 years ago

StinGer-ShoGuN commented 5 years ago

Running cron_esi.php from crontab or through php-fpm (i.e. accessing cron/cron_esi.php from a web browser) fails with the following log:

"NOTICE: PHP message: PHP Warning:  curl_error(): supplied resource is not a valid cURL handle resource in /path/to/kb/common/includes/esi/class.esisso.php on line 428"
"NOTICE: PHP message: PHP Fatal error:  Uncaught EDK\ESI\EdkSsoException: Error querying OAUTH SSO server while fetching refreshed OAUTH SSO access access token: (HTTP Code: 0) in /path/to/kb/common/includes/esi/class.esisso.php:431"
"Stack trace:"
"#0 /path/to/kb/common/includes/esi/class.esisso.php(76): EDK\ESI\ESISSO->refreshAccessToken(false)"
"#1 /path/to/kb/common/includes/esi/class.esifetch.php(62): EDK\ESI\ESISSO->__construct('1')"
"#2 /path/to/kb/common/includes/esi/class.esifetch.php(86): EDK\ESI\ESIFetch::getByID('1')"
"#3 /path/to/kb/cron/cron_esi.php(27): EDK\ESI\ESIFetch::getAll()"
"#4 {main}"
"  thrown in /path/to/kb/common/includes/esi/class.esisso.php on line 431"

I have PHP 7.1.22 and curl 7.61.1. I think I made an update on curl not so long ago, and this is when the issue arose.

It seems the problem is caused by IPv6: curl is looking for an AAAA record for esi.evetech.com, which does not exist. The solution is to tell curl to use IPv4 and look fo an A record.

When I have time, I will try to add this settings to curl configuration. In the meantime, if someone wants to fix it, I'll be more than happy.

Salvoxia commented 5 years ago

Hi,

nice catch! Could you please check if this resolves the issue? https://github.com/evekb/evedev-kb/commit/b9b155f864b7a1b419d51d32f7d30285c99bb9ab

Best Regards, Salvoxia

StinGer-ShoGuN commented 5 years ago

Sorry for the Close/Open: I misclicked (yeah, I know, I need new fingers, maybe new brain as well...).

StinGer-ShoGuN commented 5 years ago

Regarding the commit, nope, it doesn't solve the issue.

Also forgot to mention that it also affects the "Fetch kills" button in the SSO Keys page of the admin panel.

Now, I said the issue was with curl and IPv6 but I might be wrong...

Digging a bit further, I find that curl_close is called too early: the handle is closed on line 424 in class_esisso.php, but accessed further on line 428 if there is no result. I created pull request #99 to fix this. Now, the message changes to:

"NOTICE: PHP message: PHP Fatal error:  Uncaught EDK\ESI\EdkoException: Error querying OAUTH SSO server while fetching refreshed OAUTH SSO access access token: Could not resolve host: login.eveonlincom(HTTP Code: 0) in /path/to/kb/common/includes/esi/class.esisso.php:430"
"Stack trace:"
"#0 /path/to/kb/common/includes/e/class.esisso.php(76): EDK\ESI\ESISSO->refreshAccessToken(false)"
"#1 /path/to/kb/common/includes/e/class.esifetch.php(62): EDK\ESI\ESISSO->__construct('1')"
"#2 /path/to/kb/common/includes/e/class.esifetch.php(86): EDK\ESI\ESIFetch::getByID('1')"
"#3 /path/to/kb/cron/cron_esi.php7): EDK\ESI\ESIFetch::getAll()"
"#4 {main}"
"  thrown in /path/to/kb/common/iludes/esi/class.esisso.php on line 430"

Which is what led me to say it was an IPv6 related issue.

I need to dig this further to find the core issue.

Salvoxia commented 5 years ago

Well, it might still be an IPv6 issue, since silly me didn't remember that cURL is used in different places. Your error was thrown when refreshing the access token, and there the IPv4 IP resolution setting is not present. Might still be worth a try.