Ability to "close" sockets without dropping pending requests #874
Replies: 3 comments 4 replies
-
import { App, us_listen_socket_close } from 'uWebSockets.js';
let listenSocket;
const app = App().listen(port, s => listenSocket = s);
// block new requests
us_listen_socket_close(listenSocket); |
Beta Was this translation helpful? Give feedback.
-
We could possibly consider something similar to maxLifetime where you can specify the maximum time a client can hold a http connection. We have it for websockets for this very reason but not for http |
Beta Was this translation helpful? Give feedback.
-
@tayler-king Browsers keep connections open with |
Beta Was this translation helpful? Give feedback.
-
To preface: assume no use of websockets, purely HTTP connections
I'm putting together an application that can handle automatic scaling of uWS server instances based on load. I'm binding each instance to the same port and letting
SO_REUSEPORT
do its thing.As an example, one method of scaling servers down would be to choose the uWS instance with the least amount of pending requests. By pending request I mean a request that has been accepted by the server and is being processed by the application, i.e. it is non-complete and has not finished responding to the client. Once all pending requests have been completed the instance would terminate.
The issue with the above approach is that I cannot fathom of a way to cleanly handling blocking of new requests when a uWS instance has been marked to be terminated, whilst using
SO_REUSEPORT
.Would the better option be to just run each server on its own port and have the load balancer handle failing over if a request is rejected with status 503 for example? I would like to avoid this as then I would have to deal with the dynamic port selection of servers and assigning them to the load balancer.
Beta Was this translation helpful? Give feedback.
All reactions