Skip to content
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

Close inactive connections #423

Closed

Conversation

WyriHaximus
Copy link
Member

@WyriHaximus WyriHaximus commented Aug 21, 2021

This new middleware introduces a timeout of closing inactive
connections between connections after a configured amount of seconds.

This builds on top of #405 and partially on #422

This PR very specifically doesn't deal with inactivity while handling requests, which will be proposed in a different PR.

@WyriHaximus WyriHaximus added this to the v1.6.0 milestone Aug 21, 2021
@WyriHaximus WyriHaximus force-pushed the close-inactive-connections branch 4 times, most recently from 1592cb1 to 0647b58 Compare August 22, 2021 20:22
@WyriHaximus WyriHaximus requested review from clue and jsor August 22, 2021 20:23
@WyriHaximus WyriHaximus marked this pull request as ready for review August 22, 2021 20:23
if ($data !== '') {
$loop->cancelTimer($timer);
}
});
Copy link
Member

Choose a reason for hiding this comment

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

@WyriHaximus This looks like a good starting point 👍

However, the way it's currently designed, this will only wait for some data and then wait infinitely for a complete HTTP request header. I would suggest moving this logic to the RequestHeaderParser and make the timeout apply to the entire HTTP request header. For instance, if I send GET / HTTP/1.1\r\n but nothing else, this should still run into a timeout.

Copy link
Member Author

Choose a reason for hiding this comment

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

@clue Correct, that is intentional. My initial intent was to first create this PR and do it on a connection level, and then do a follow up to do it on both the connection and request level. But if you think it would be better to do both I can fold that into this PR.

Copy link
Member

Choose a reason for hiding this comment

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

@WyriHaximus Without knowing the complete scope of this feature I would lean towards including the timeout on the request level, but I'll leave this up to you to decide 👍

Either way I think the above snippet should be updated without the if statement as the underlying socket and stream components should never emit an empty data event.

Copy link
Member Author

Choose a reason for hiding this comment

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

@clue updated the PR with that change as per your suggestion. As discussed this morning I'll also file the follow-up PR taking care of the idle request closing.

Copy link
Member Author

Choose a reason for hiding this comment

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

@clue As promised: #425

WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 1, 2021
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
});
$loop = $this->loop;
$conn->once('data', function () use ($loop, $timer) {
$loop->cancelTimer($timer);
Copy link
Member Author

Choose a reason for hiding this comment

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

Consider a 60 second timeout for all headers instead

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@WyriHaximus Thanks for the update!

Can you provide a quick update here, what's your plan for this feature with regards to #425? We've briefly discussed (off channel) that this should eventually send a 408 Request Timeout response for the initial connection but not for keep-alive connections that send no following request. I agree breaking this up into smaller PRs can be useful, but it looks like this might also work in a single PR, so I'll leave this up to you. Let me know if there's anything I can help with and/or if you want me to take over from here 👍

Comment on lines +154 to +156
$conn->on('end', function () use ($loop, $timer) {
$loop->cancelTimer($timer);
});
Copy link
Member

Choose a reason for hiding this comment

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

This should be unneeded given the end event will always be followed by the close event which is handled the same way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will drop this one 👍

WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Nov 9, 2021
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
This new middleware introduces a timeout of closing inactive
connections between connections after a configured amount of seconds.

This builds on top of reactphp#405 and partially on reactphp#422
@WyriHaximus
Copy link
Member Author

@WyriHaximus Thanks for the update!

Can you provide a quick update here, what's your plan for this feature with regards to #425? We've briefly discussed (off channel) that this should eventually send a 408 Request Timeout response for the initial connection but not for keep-alive connections that send no following request. I agree breaking this up into smaller PRs can be useful, but it looks like this might also work in a single PR, so I'll leave this up to you. Let me know if there's anything I can help with and/or if you want me to take over from here +1

@clue Will fold it into a single PR, and will be adding the 408 next 👍

WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Nov 10, 2021
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Nov 10, 2021
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Nov 10, 2021
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
@clue clue removed this from the v1.6.0 milestone Feb 3, 2022
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 21, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 22, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 22, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 22, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 29, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 29, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Mar 30, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 16, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 17, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 17, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 17, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 18, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
@WyriHaximus WyriHaximus added this to the v1.8.0 milestone Aug 22, 2022
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 27, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 27, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Aug 27, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 14, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 14, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 14, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 14, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 14, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
WyriHaximus added a commit to WyriHaximus-labs/http that referenced this pull request Sep 14, 2022
This builds on top of reactphp#405 and further builds out reactphp#423 by also
close connections with inactive requests.
@clue clue removed this from the v1.8.0 milestone Sep 29, 2022
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.

None yet

2 participants