{"action":"created","issue":{"url":"https://api.github.com/repos/jedisct1/libsodium-php/issues/94","repository_url":"https://api.github.com/repos/jedisct1/libsodium-php","labels_url":"https://api.github.com/repos/jedisct1/libsodium-php/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/jedisct1/libsodium-php/issues/94/comments","events_url":"https://api.github.com/repos/jedisct1/libsodium-php/issues/94/events","html_url":"https://github.com/jedisct1/libsodium-php/issues/94","id":168438558,"number":94,"title":"libsodium module times out at system boot","user":{"login":"stevendesu","id":1384974,"avatar_url":"https://avatars.githubusercontent.com/u/1384974?v=3","gravatar_id":"","url":"https://api.github.com/users/stevendesu","html_url":"https://github.com/stevendesu","followers_url":"https://api.github.com/users/stevendesu/followers","following_url":"https://api.github.com/users/stevendesu/following{/other_user}","gists_url":"https://api.github.com/users/stevendesu/gists{/gist_id}","starred_url":"https://api.github.com/users/stevendesu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevendesu/subscriptions","organizations_url":"https://api.github.com/users/stevendesu/orgs","repos_url":"https://api.github.com/users/stevendesu/repos","events_url":"https://api.github.com/users/stevendesu/events{/privacy}","received_events_url":"https://api.github.com/users/stevendesu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-30T00:35:02Z","updated_at":"2016-07-30T01:29:58Z","closed_at":null,"body":"I'm using Ubuntu 16.04 on a VPS hosted by DigitalOcean. After four days I've managed to narrow down my issues to the libsodium-php module\r\n\r\nAfter spinning up a **brand new VPS** (nothing installed except Ubuntu 16.04, no custom hardware config, nothing out of the ordinary) I log into root and run the following set of commands:\r\n\r\n```\r\napt-get install php7.0 php7.0-dev php-pear\r\napt-get install libsodium-dev\r\npecl install libsodium\r\necho \"extension=libsodium.so\" >> /etc/php/7.0/fpm/php.ini\r\nshutdown -r 0\r\n```\r\n\r\nWhen the server restarts, check on the php7.0-fpm service:\r\n\r\n**During startup**\r\n```\r\nroot@simple-test:~# service php7.0-fpm status\r\n● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager\r\n   Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)\r\n   Active: activating (start-pre) since Fri 2016-07-29 20:20:42 EDT; 47s ago\r\n  Control: 2287 (php7.0-fpm-chec)\r\n    Tasks: 4\r\n   Memory: 13.0M\r\n      CPU: 46ms\r\n   CGroup: /system.slice/php7.0-fpm.service\r\n           └─control\r\n             ├─2287 /bin/sh /usr/lib/php/php7.0-fpm-checkconf\r\n             ├─2296 /bin/sh /usr/lib/php/php7.0-fpm-checkconf\r\n             ├─2297 /usr/sbin/php-fpm7.0 --fpm-config /etc/php/7.0/fpm/php-fpm.conf -t\r\n             └─2298 grep \\[ERROR\\]\r\n\r\nJul 29 20:20:42 simple-test systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...\r\n```\r\n\r\n**After failure**\r\n```\r\nroot@simple-test:~# service php7.0-fpm status\r\n● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager\r\n   Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)\r\n   Active: failed (Result: timeout) since Fri 2016-07-29 20:22:13 EDT; 1min 4s ago\r\n  Process: 2287 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=killed, signal=TERM)\r\n\r\nJul 29 20:20:42 simple-test systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...\r\nJul 29 20:22:13 simple-test systemd[1]: php7.0-fpm.service: Start-pre operation timed out. Terminating.\r\nJul 29 20:22:13 simple-test systemd[1]: Failed to start The PHP 7.0 FastCGI Process Manager.\r\nJul 29 20:22:13 simple-test systemd[1]: php7.0-fpm.service: Unit entered failed state.\r\nJul 29 20:22:13 simple-test systemd[1]: php7.0-fpm.service: Failed with result 'timeout'.\r\n```\r\n\r\nNote that after it has failed I can manually run `service php7.0-fpm start` and it stats up in milliseconds. This is an issue that **only occurs at boot time**"},"comment":{"url":"https://api.github.com/repos/jedisct1/libsodium-php/issues/comments/236330933","html_url":"https://github.com/jedisct1/libsodium-php/issues/94#issuecomment-236330933","issue_url":"https://api.github.com/repos/jedisct1/libsodium-php/issues/94","id":236330933,"user":{"login":"stevendesu","id":1384974,"avatar_url":"https://avatars.githubusercontent.com/u/1384974?v=3","gravatar_id":"","url":"https://api.github.com/users/stevendesu","html_url":"https://github.com/stevendesu","followers_url":"https://api.github.com/users/stevendesu/followers","following_url":"https://api.github.com/users/stevendesu/following{/other_user}","gists_url":"https://api.github.com/users/stevendesu/gists{/gist_id}","starred_url":"https://api.github.com/users/stevendesu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevendesu/subscriptions","organizations_url":"https://api.github.com/users/stevendesu/orgs","repos_url":"https://api.github.com/users/stevendesu/repos","events_url":"https://api.github.com/users/stevendesu/events{/privacy}","received_events_url":"https://api.github.com/users/stevendesu/received_events","type":"User","site_admin":false},"created_at":"2016-07-30T01:29:58Z","updated_at":"2016-07-30T01:29:58Z","body":"Continuing to look into this:\r\n\r\nTracing the startup process, I found that in `/lib/systemd/system/php7.0-fpm.service` it called `/usr/lib/php/php7.0-fpm-checkconf` which gets to the following line before timing out:\r\n\r\n```\r\nerrors=$(/usr/sbin/php-fpm7.0 --fpm-config \"$CONFFILE\" -t 2>&1 | grep \"\\[ERROR\\]\" || true);\r\n```\r\n\r\nAttempting to run `/usr/sbin/php-fpm7.0 --fpm-config \"$CONFFILE\" -t 2>&1` manually during the first 2-3 minutes after server boot just stalls.\r\n\r\nI noticed that if I also put `extension=libsodium.so` into cli/php.ini then for the same first 2-3 minutes after the server boots I can't run `php -v`. It seems like PHP is stalling out in its entirety during this time.\r\n\r\nLooking at `libsodium.c` it looks like the `PHP_MINIT_FUNCTION` does nothing but call `sodium_init()`, so I suspect `sodium_init()` is taking 2-3 minutes to complete. Looking at `sodium_init()` in the sodium repo it's calling multiple functions, and I'm not sure how to profile it to see which function is taking so long:\r\n\r\n```\r\n    randombytes_stir();\r\n    _sodium_alloc_init();\r\n    _crypto_pwhash_argon2i_pick_best_implementation();\r\n    _crypto_generichash_blake2b_pick_best_implementation();\r\n    _crypto_onetimeauth_poly1305_pick_best_implementation();\r\n    _crypto_scalarmult_curve25519_pick_best_implementation();\r\n    _crypto_stream_chacha20_pick_best_implementation();\r\n```\r\n\r\nSince libsodium is a security library, I don't feel safe trying to muck with it and still trust it to be secure, so for all intents and purposes I think it's safe to assume it will **require** 2-3 minutes to start up before we can use PHP. That said, this is preventing php-fpm from loading at system start, forcing me to log into the server and start it manually after a server reboot!\r\n\r\nIs it possible for libsodium-php be modified so as to not block when libsodium is uninitialized, and instead throw an exception or an error? The odds of someone accessing a page requiring libsodium-php within the 2 minutes after a server reboot are low enough I could accept the server temporarily throwing a 500 error during this time: but throwing a 502 for hours until I log in to manually run php-fpm is problematic."}}
{"actor":{"display_login":"stevendesu"}}