Commit 35d28fb5 authored by Jukka Rissanen's avatar Jukka Rissanen
Browse files

net: http: Connection close fix if old connection is active



If we receive a HTTP request and if the earlier context is still
active and it is not the same as the new one, then close the earlier
one. Otherwise it is possible that the old context will be left into
TCP ESTABLISHED state and would never be released. Example of this
is that we had IPv4 connection active and then IPv6 connection is
established, in this case we will disconnect the IPv4 connection
after this commit.

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@linux.intel.com>
parent 87ccb79a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ static void req_timeout(struct k_work *work)
	NET_DBG("Context %p request timeout", ctx);

	net_context_unref(ctx->req.net_ctx);
	ctx->req.net_ctx = NULL;

	http_server_conn_del(ctx);
}
@@ -737,6 +738,19 @@ static void accept_cb(struct net_context *net_ctx,
		return;
	}

	/* If we receive a HTTP request and if the earlier context is still
	 * active and it is not the same as the new one, then close the earlier
	 * one. Otherwise it is possible that the context will be left into
	 * TCP ESTABLISHED state and would never be released. Example of this
	 * is that we had IPv4 connection active and then IPv6 connection is
	 * established, in this case we disconnect the IPv4 here.
	 */
	if (http_ctx->req.net_ctx && http_ctx->req.net_ctx != net_ctx &&
	    net_context_get_state(http_ctx->req.net_ctx) ==
						      NET_CONTEXT_CONNECTED) {
		net_context_unref(http_ctx->req.net_ctx);
	}

	http_ctx->req.net_ctx = net_ctx;

	new_client(http_ctx, net_ctx, addr);