-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Http2Server.prototype.close Does Not Work as Expected #28214
Comments
I guess it wasn't documented because the behavior is the same of |
I think this is behaving as documented. |
Oh, I see, it is documented. The callback is called when the server is closed, and the server waits, until there is no active connection, to close. But I think the point is not whether it is documented or not: An asynchronous operation usually call its callback function right after the operation is done. As Of course, it is not common does not mean it is bad. But think of the following situation: Now I want to force a server to be closed with the following algorithm:
The second step must be executed after the first step. As the first step is an asynchronous operation, I would wait for its callback function to be called, to ensure that it is done. But the callback is called also implies that the second step is done. It is a dead lock. Another approach:
It will not work, because once the server is still accepting new connections, there is no way to close all active connections in finite amount of steps. |
There is no need to wait for the callback before closing connections. No new connection is established after |
If the function is defined to "stop the server from accepting new connections and keep existing connections", and the work is done before it returns, I would rather say that it is synchronous instead of asynchronous; saying that it is asynchronous means that, only through waiting that callback, I can ensure the work is done. However, the function is named
|
This commit is an attempt to clarify the behavior of HTTP2's server.close() method. Specifically, this makes it more clear that the server stops allowing new sessions although the callback may not be invoked for some time due to previously existing sessions. PR-URL: nodejs#28581 Fixes: nodejs#28214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is an attempt to clarify the behavior of HTTP2's server.close() method. Specifically, this makes it more clear that the server stops allowing new sessions although the callback may not be invoked for some time due to previously existing sessions. PR-URL: #28581 Fixes: #28214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
node-v12.4.0-linux-x64/bin/node a.js
Expected:
server.close
stops the server from accepting new connections.Result:
console.log('close')
never get called.I aware that HTTP/2 works different to HTTP/1.1. And I can and should call
session.close()
on every active session to stop them from accepting new requests.server.close
seems also wait until there is no active sessions to call the callback function, which is not mentioned in the documentation.And, to make there is no active sessions, I must first of all stop the server from accepting new connections.
The text was updated successfully, but these errors were encountered: