Skip to content

Add warning to log, when fpm socket was not registered on the expected path #11066

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

Conversation

JoshuaBehrens
Copy link
Contributor

I decided it to be a warning, because you can still run against the newly created socket file but fail it for the configuration test. It felt right to do it like that.

Where am I coming from?

I have an experiments folder deep down in a folder structure on my work machine (/home/name/projects/delete-to-free-storage/experiments). In there I cloned a project where I wanted to try out devenv for a part in a subfolder (/home/name/projects/delete-to-free-storage/experiments/foobar/php-web). I set up devenv, it uses process-compose to orchestrate php-fpm for me and it places the php-fpm socket file in a project specific sub directory (/home/name/projects/delete-to-free-storage/experiments/foobar/php-web/.devenv/state/php-fpm/web). When I opened up the nginx served page, all I get is a white page and nginx prints into the log dialing backend: dial unix /home/name/projects/delete-to-free-storage/experiments/foobar/php-web/.devenv/state/php-fpm/web.sock: connect: invalid argument.

So now try to debug this. You have multiple sources for this error (devenv, process-compose, nix, a nix package for php, php itself, nginx, a nix package for nginx). I was looking into to this with @jochenmanz for several days. Our question was: "Why is the file extension missing?" We were looking through the different tools but no solution

Just today I just received the message "What OS are you on and did you know that socket file names are limited in length?" After just moving the project into a directory with a shorter path, we saw, that it was working and the socket file had the .sock extension as expected. "the extension .sock was missing" is just a coincidence in after a string length cut. So we found the issue it was on binding the socket. We found some checks against in php for every socket access. But for some reason not for php-fpm. The socket will just get cut off. So I decided to fix that so have other people minds less stressed :)

Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

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

It makes sense but needs some tests.

@JoshuaBehrens
Copy link
Contributor Author

@bukka I am happy to write some tests for it. Can you give me a reference test that I can copy or extend for my feature?

@bukka
Copy link
Member

bukka commented Apr 17, 2023

Check this one out: https://github.com/php/php-src/blob/414f71a90254cc33896bb3ba953f979f743c198c/sapi/fpm/tests/socket-uds-numeric-ugid-nonroot.phpt . It should hopefully give you some idea. You will need to create a custom address so something with a long suffix should hopefully do.

@JoshuaBehrens
Copy link
Contributor Author

Hi @bukka I created two tests. One for actually running fpm and one for the test. I added a section in the upgrade notes. I am up to any wording changes :) With this I noticed I affected other tests as well. For example I broke bug68591-conf-test-listen-group.log:

ERROR: [pool unconfined] cannot get gid for group 'aaaaaa': %s
ERROR: FPM initialization failed
Done
---- ACTUAL OUTPUT
ERROR: [pool unconfined] cannot bind to UNIX socket '/var/folders/7j/lfxr9fd12tn1lcfj3bl9f_7r0000gn/T/nix-shell.XXXXXX.mu6K44Ew/5cf922da-bug68591-conf-test-listen-group.9008.sock' as path is too long (found length: 125, maximal length: 104)
ERROR: FPM initialization failed

I was able to unbreak it but therefore I changed code in the Tester class. This might affect more than I can grasp right now but it fights the fact on Mac the temp folder is not /tmp and therefore not a shorter but rather longer option for a socket file path.

Sidenote: Are you interested in feedback on my experience as first time contributor?

@iluuu1994
Copy link
Member

Sidenote: Are you interested in feedback on my experience as first time contributor?

We're definitely interested in making contributions a more pleasant experience for everyone. 🙂 Let me know if there's something we can improve.

@JoshuaBehrens
Copy link
Contributor Author

JoshuaBehrens commented Apr 27, 2023

@iluuu1994 thank you :) for taking the feedback:
I am not sure where I would find that info in the first place but I did not really find a guide how to make a pull request for this project. I had to figure out which configure options worked out for my development setup. I run make test a lot and had to wait a lot. At some time during writing tests I stumbled upon https://qa.php.net/ which helped me to find minimal configure options in the cron example and run a single test. The page helped me a lot although the preamble is basically: "you have no idea how to write c? No worries, testing is simple." Thrive to investigation and digging into it helped me to stay on this topic. I am not sure whether this is the contributor experience you want to provide or whether this is intentional gate keeping to ensure a certain level of expertise. Likely I was just searching for the wrong terms and the search engine did not gave me helpful results. Maybe there is also an entrypoint for my kind of persona missing and therefore I could not find it. I hope this is helpful feedback :)

@iluuu1994
Copy link
Member

There's https://www.phpinternalsbook.com/, which is likely the most up to date resource atm. But that doesn't help much when it's linked nowhere 😄 Adding a basic contributors guide is certainly a good idea.

@JoshuaBehrens
Copy link
Contributor Author

Without having a detailed look into it it looks promising :D I will give it a go next time I am up to change something

@iluuu1994
Copy link
Member

@JoshuaBehrens I created a PR here: #11155 Feel free to comment if you have any other suggestions!

Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

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

The C part looks good. Just the tests need some changes (mostly smaller one - it looks good in general).

Comment on lines 35 to 38
$files = [];

foreach (glob($socketFilePrefix . '*') as $file) {
$files[] = $file;
}
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Can't you just do this:

Suggested change
$files = [];
foreach (glob($socketFilePrefix . '*') as $file) {
$files[] = $file;
}
$files = glob($socketFilePrefix . '*');

Comment on lines 76 to 61
$socketFile = $socketFilePrefix . '-that-is-too-long-0000-1111-2222-3333-4444-5555-6666-7777-8888-9999-aaaa-bbbb-cccc-dddd-eeee-ffff-gggg-hhhh-iiii.sock';

if (is_file($socketFile)) {
Copy link
Member

Choose a reason for hiding this comment

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

is this actually correct if it creates trimmed file? It should probably glob it and delete the trimmed file, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this actually correct if it creates trimmed file? this is what happens already today. I just try to make one aware of it so one can bind to the right socket

@JoshuaBehrens
Copy link
Contributor Author

I rebased and amend the code in previous commits so it is a bit cleaner to read the history.

I suggest an UPGRADE notice like:

- Parsing of invalid values will now trigger a warning when this was silently
  ignored before. Interpretation of these values is not changed, for
  backwards compatibility. Testing configuration can fail though.
  This affects the following settings:
  . {fpm_pool}.listen

@JoshuaBehrens JoshuaBehrens force-pushed the feature/cut-fpm-socket-path-warning branch from 70c3036 to 4396f3d Compare May 20, 2023 13:10
Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

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

Apology for slightly late review. Completely forgot about this when doing FPM stuff last month... Just some minor suggestions and one question added.

@JoshuaBehrens JoshuaBehrens force-pushed the feature/cut-fpm-socket-path-warning branch from 4396f3d to 0cb3074 Compare June 29, 2023 07:51
@JoshuaBehrens
Copy link
Contributor Author

I rebased, amend previous commits to the given feedback.

I hope I got the helper for the socket directory into a more welcome solution. I need feedback on the log type so I can amend this as well :)

This might happen if the UDS length limit is exceeded.

Co-authored-by: Jakub Zelenka <[email protected]>

Closes phpGH-11066
@bukka bukka force-pushed the feature/cut-fpm-socket-path-warning branch from 0cb3074 to 4aa1bf9 Compare July 15, 2023 12:11
@bukka bukka closed this in 08b5777 Jul 15, 2023
@bukka
Copy link
Member

bukka commented Jul 15, 2023

So I have been testing this and it was actually failing due to incorrect test (the one for FPM test error check) which I needed to rewrite. Also pipeline build was failing because it requires using %zu when formatting size_t which I also fixed. I did some few other things as well (CS, test formatting and that extra test check). I have done all those changes myself as the feature freeze is on Tuesday so it can get to 8.3. After that pipeline was green so it is all merged now! Thanks for you work!

@JoshuaBehrens
Copy link
Contributor Author

Thank you for the collaborative work and investment to get it in before the feature freeze <3

@andypost
Copy link
Contributor

andypost commented Jul 18, 2023

Trying to build for Alpinelinux getting the test to fail

TEST 16510/16569 [sapi/fpm/tests/socket-uds-too-long-filename-start.phpt]
========DIFF========
+ Socket files were not found.
+
+ Warning: Undefined array key 0 in /builds/alpine/aports/testing/php83/src/php-src-0b0cec5b8a920bafa07dd702950a092a8811596d/sapi/fpm/tests/socket-uds-too-long-filename-start.php on line 41
     Done
========DONE========
[FAIL FPM: UNIX socket filename is too for start [sapi/fpm/tests/socket-uds-too-long-filename-start.phpt] 

@andypost
Copy link
Contributor

Running within /builds/alpine fails as well as /mnt0123456789 - so length to source should be less then 88 chars

@andypost
Copy link
Contributor

That's because socket maxpath is 108 chars

@JoshuaBehrens JoshuaBehrens deleted the feature/cut-fpm-socket-path-warning branch September 25, 2023 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants