Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp625411pxy; Wed, 28 Apr 2021 10:43:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDKWS9zG/uaSw9/5MB0aV2EvnGlCSUuZO7u7HUb9m/yGgRsDI+i8Eb0/kmOkv3yZNXl0aH X-Received: by 2002:a05:6402:10d8:: with SMTP id p24mr4760574edu.337.1619631788940; Wed, 28 Apr 2021 10:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619631788; cv=none; d=google.com; s=arc-20160816; b=xSH7ouycEk7ua9+OCAs3w87ns0RBWf2Jad6dFi34qcxpjcdKsZaauIrH3KXOgButwn O92Uh8/ugeubnODXsuSHGpr1V1yclOVRiOsv0BIZCfu7CbjiQxwiU297cbNRHMPILN7m G6hZl6cxaNry/nuYEyz6mdOwheDZTsihl2lPw/kfLhFRfND2MSLv6F0rQ+F6ztwBQtkS R/DZAzuwpyEImUDrCM3MljvNiPemowqkaCA/BaKUFSAXIqZf6gjM/zDN8QS52F5froMR kwrLT9s+gB1hyeGzcxol8BNamCOnEPCyM18ryGQjaqHt+K1ec1gqDLxfKBRjw8AlTke7 9swA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aTy9+SvPIGV5lFvSWx3LUU1Noi5i+O1/6N3XRc6Yp+s=; b=JdF/L1SvoZNyIYPJ+2bnxlJz8SAIAmftnua+qAqXwetZ10Vw7GmReHyPP5e/VLTpYz AmLi1QE5qx5nyU5SrG5CIMplRobx2gRMc4fn+fgYoU+J/lPyMTqPoMN8AiteUy4Ysj7e cIDZftyop3p2SRUUsy7nTaU9bUXQQcYCu5W7wm1WkdP0WQCRu327z1EJURv4GCS7Y5MQ E7zJOPq04KPk/O9taJm7LvIvTZbxZ/Sshk8yfaHOYWCwZ7TUWdCf43ySOTFleN1awrlx CJ2PgdFb7OCDnwNAOOZRVOotVmK1nUb4z6adIQrUqGvAz9s025mpFI3zP5rNVvioh2Q4 ajPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U4cWdJbn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k9si339389edq.266.2021.04.28.10.42.44; Wed, 28 Apr 2021 10:43:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U4cWdJbn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241063AbhD1Qeb (ORCPT + 99 others); Wed, 28 Apr 2021 12:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241054AbhD1Qea (ORCPT ); Wed, 28 Apr 2021 12:34:30 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C786FC061573 for ; Wed, 28 Apr 2021 09:33:44 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id z1so74659756ybf.6 for ; Wed, 28 Apr 2021 09:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aTy9+SvPIGV5lFvSWx3LUU1Noi5i+O1/6N3XRc6Yp+s=; b=U4cWdJbnMYockksal5W0qWJ2/o3nLv4Lpk4cU+XKGbqMzFEDbp2Bx5blybQ6IenHy/ JCNxwlpGYWOUVPfdYVzj/m4OnSC4V7s5jz8MmW2I6akFZKirqRk8ups8VD9olaeIqMTC w50SxBvWF4kkuIsqyKSuw7Kf0MS552kN6OaZgPxsKL5QNsMn7dlMZSbRBW3isDSraZyz 3COqcLh12yU4ZJiwgAEhEidLiRAtdm9+6MQzTeRCl0ePVeSnNQaCRLoo2hhKahQ/qczq v5VpyIc/F/X6QHkzATVBJgptzCxjSsO0Me0zur5U//06nWHYkFhxuKazsfyigLDdfXPM pdEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aTy9+SvPIGV5lFvSWx3LUU1Noi5i+O1/6N3XRc6Yp+s=; b=rddimfstN4uJyrPoag85JlX28k3qhRJIhreVhNg9h9nMVY4sAPLBJWpgDh/lzWaH/q /Ln86fEXnCVoBh6cdZtuJmcxTcAtIxxI67n++Mto+/P0DX766G24gjiu++Gveht1/n6v b0oLCn2xQq6KT5/LH3laVmcQWk9ZNfAqmQqu2E2QT7ezwD9pHjLHSWAJtUOsxvkvQ5jX 1bvil6NOo4Do7F+DfvtrPSq5UYDev9AsKQ+280pkJNwxycvhowKuHENiFtEZApBTPdX/ DQ6li2J5Y3Jzj2vb0US6d9dUdzjOn99dcbtRQLOHX/tXiORqo8V01R1uSXoCtEHnja8+ w5VA== X-Gm-Message-State: AOAM530cqbRYMF/ow8xI66jwT1Ax3jMUbce1Fp6g1cP3Aw9htBTM0NX3 o6YJqP97AWKHEAMZX/GvMGDiiOsbGO2XYngz/gduxw== X-Received: by 2002:a5b:906:: with SMTP id a6mr33493576ybq.446.1619627623685; Wed, 28 Apr 2021 09:33:43 -0700 (PDT) MIME-Version: 1.0 References: <20210428155203.39974-1-kuniyu@amazon.co.jp> In-Reply-To: <20210428155203.39974-1-kuniyu@amazon.co.jp> From: Eric Dumazet Date: Wed, 28 Apr 2021 18:33:32 +0200 Message-ID: Subject: Re: [PATCH v4 bpf-next 00/11] Socket migration for SO_REUSEPORT. To: Kuniyuki Iwashima Cc: Jason Baron , andrii@kernel.org, Alexei Starovoitov , Benjamin Herrenschmidt , bpf , Daniel Borkmann , David Miller , Martin KaFai Lau , Jakub Kicinski , Kuniyuki Iwashima , LKML , netdev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 28, 2021 at 5:52 PM Kuniyuki Iwashima wrote: > > From: Jason Baron > Date: Wed, 28 Apr 2021 10:44:12 -0400 > > On 4/28/21 4:13 AM, Kuniyuki Iwashima wrote: > > > From: Jason Baron > > > Date: Tue, 27 Apr 2021 12:38:58 -0400 > > >> On 4/26/21 11:46 PM, Kuniyuki Iwashima wrote: > > >>> The SO_REUSEPORT option allows sockets to listen on the same port and to > > >>> accept connections evenly. However, there is a defect in the current > > >>> implementation [1]. When a SYN packet is received, the connection is tied > > >>> to a listening socket. Accordingly, when the listener is closed, in-flight > > >>> requests during the three-way handshake and child sockets in the accept > > >>> queue are dropped even if other listeners on the same port could accept > > >>> such connections. > > >>> > > >>> This situation can happen when various server management tools restart > > >>> server (such as nginx) processes. For instance, when we change nginx > > >>> configurations and restart it, it spins up new workers that respect the new > > >>> configuration and closes all listeners on the old workers, resulting in the > > >>> in-flight ACK of 3WHS is responded by RST. > > >> > > >> Hi Kuniyuki, > > >> > > >> I had implemented a different approach to this that I wanted to get your > > >> thoughts about. The idea is to use unix sockets and SCM_RIGHTS to pass the > > >> listen fd (or any other fd) around. Currently, if you have an 'old' webserver > > >> that you want to replace with a 'new' webserver, you would need a separate > > >> process to receive the listen fd and then have that process send the fd to > > >> the new webserver, if they are not running con-currently. So instead what > > >> I'm proposing is a 'delayed close' for a unix socket. That is, one could do: > > >> > > >> 1) bind unix socket with path '/sockets' > > >> 2) sendmsg() the listen fd via the unix socket > > >> 2) setsockopt() some 'timeout' on the unix socket (maybe 10 seconds or so) > > >> 3) exit/close the old webserver and the listen socket > > >> 4) start the new webserver > > >> 5) create new unix socket and bind to '/sockets' (if has MAY_WRITE file permissions) > > >> 6) recvmsg() the listen fd > > >> > > >> So the idea is that we set a timeout on the unix socket. If the new process > > >> does not start and bind to the unix socket, it simply closes, thus releasing > > >> the listen socket. However, if it does bind it can now call recvmsg() and > > >> use the listen fd as normal. It can then simply continue to use the old listen > > >> fds and/or create new ones and drain the old ones. > > >> > > >> Thus, the old and new webservers do not have to run concurrently. This doesn't > > >> involve any changes to the tcp layer and can be used to pass any type of fd. > > >> not sure if it's actually useful for anything else though. > > >> > > >> I'm not sure if this solves your use-case or not but I thought I'd share it. > > >> One can also inherit the fds like in systemd's socket activation model, but > > >> that again requires another process to hold open the listen fd. > > > > > > Thank you for sharing code. > > > > > > It seems bit more crash-tolerant than normal fd passing, but it can still > > > suffer if the process dies before passing fds. With this patch set, we can > > > migrate children sockets even if the process dies. > > > > > > > I don't think crashing should be much of an issue. The old server can setup the > > unix socket patch '/sockets' when it starts up and queue the listen sockets > > there from the start. When it dies it will close all its fds, and the new > > server can pick anything up any fds that are in the '/sockets' queue. > > > > > > > Also, as Martin said, fd passing tends to make application complicated. > > > > > > > It may be but perhaps its more flexible? It gives the new server the > > chance to re-use the existing listen fds, close, drain and/or start new > > ones. It also addresses the non-REUSEPORT case where you can't bind right > > away. > > If the flexibility is really worth the complexity, we do not care about it. > But, SO_REUSEPORT can give enough flexibility we want. > > With socket migration, there is no need to reuse listener (fd passing), > drain children (incoming connections are automatically migrated if there is > already another listener bind()ed), and of course another listener can > close itself and migrated children. > > If two different approaches resolves the same issue and one does not need > complexity in userspace, we select the simpler one. Kernel bloat and complexity is _not_ the simplest choice. Touching a complex part of TCP stack is quite risky.