Skip to content

Conversation

@dyeldandi
Copy link
Contributor

Retargeting PR #2375

@dyeldandi dyeldandi mentioned this pull request Feb 9, 2017
@krakjoe krakjoe added the Bug label Feb 9, 2017
@dyeldandi
Copy link
Contributor Author

@nikic

I'm not familiar with the fastcgi code, just trying to figure out how all this works... Looking at the current implementation of fcgi_accept_request, if fd < 0, we are first calling on_accept() then accept(), then on_read(), then poll() or select(), then fcgi_read_request(). If fd >= 0, then only fcgi_read_request() is called.

This patch changes to call on_read() also after fcgi_read_request(). However, doesn't that mean that in the case of fd < 0, we will end up calling on_read() twice? Similarly, should on_read be called before fcgi_read_request() or after?

doesn't that mean that in the case of fd < 0, we will end up calling on_read() twice

That can be the case, yes. Current implementation of php-fpm uses this hook just to zero variables, so it's not a problem. But if you think this should fire only once I can dig into it...

Similarly, should on_read be called before fcgi_read_request() or after?

Again, since it's just resetting variables it doesn't matter as far as I understand. But I don't know what the author of that code really wanted for this hook.

@nikic
Copy link
Member

nikic commented Feb 9, 2017

@dyeldandi You're right that fpm_request_reading_headers() doesn't seem to do anything particularly critical, so doing two calls won't break things too badly. However it will probably mess with the statistics, as these increments will be done twice.

@dyeldandi
Copy link
Contributor Author

@nikic
Ah, yes, you are right there. Lemme run a bit of debug to check it and fix it if that's the case.

if (UNEXPECTED(max_requests && (requests == max_requests))) {
fcgi_finish_request(request, 1);
fcgi_request_set_keep(request, 0);
fcgi_finish_request(request, 0);
Copy link
Member

Choose a reason for hiding this comment

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

This looks reasonable. Should the same change also be done here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, yeah, looks like. Although I don't use CGI SAPI and never looked into that code, so I can't really say.

@nikic nikic self-assigned this Feb 9, 2017
@dyeldandi
Copy link
Contributor Author

dyeldandi commented Feb 10, 2017

@nikic

doesn't that mean that in the case of fd < 0, we will end up calling on_read() twice

Yeah, it is being called twice when a new connection arrives, which does mess up the statistics.
I moved this event to just before fcgi_read_request().

@nikic
Copy link
Member

nikic commented Feb 11, 2017

Merged via 9814be4, thanks!

@nikic nikic closed this Feb 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants