Commit cdb65889 authored by Sergey Lyubka's avatar Sergey Lyubka

Fix to stop misbehaving clients to DoS mongoose

parent eecf24b2
......@@ -4632,9 +4632,12 @@ static void reset_per_request_attributes(struct mg_connection *conn) {
}
static void close_socket_gracefully(struct mg_connection *conn) {
#if defined(_WIN32)
char buf[MG_BUF_LEN];
int n;
#endif
struct linger linger;
int n, sock = conn->client.sock;
int sock = conn->client.sock;
// Set linger option to avoid socket hanging out after close. This prevent
// ephemeral port exhaust problem under high QPS.
......@@ -4646,6 +4649,7 @@ static void close_socket_gracefully(struct mg_connection *conn) {
(void) shutdown(sock, SHUT_WR);
set_non_blocking_mode(sock);
#if defined(_WIN32)
// Read and discard pending incoming data. If we do not do that and close the
// socket, the data in the send buffer may be discarded. This
// behaviour is seen on Windows, when client keeps sending data
......@@ -4654,6 +4658,7 @@ static void close_socket_gracefully(struct mg_connection *conn) {
do {
n = pull(NULL, conn, buf, sizeof(buf));
} while (n > 0);
#endif
// Now we know that our FIN is ACK-ed, safe to close
(void) closesocket(sock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment