From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D04EC35242 for ; Sat, 8 Feb 2020 20:43:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6639F22522 for ; Sat, 8 Feb 2020 20:43:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=scylladb-com.20150623.gappssmtp.com header.i=@scylladb-com.20150623.gappssmtp.com header.b="d2+WG0L3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727473AbgBHUnw (ORCPT ); Sat, 8 Feb 2020 15:43:52 -0500 Received: from mail-lf1-f54.google.com ([209.85.167.54]:43563 "EHLO mail-lf1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgBHUnw (ORCPT ); Sat, 8 Feb 2020 15:43:52 -0500 Received: by mail-lf1-f54.google.com with SMTP id 9so1554972lfq.10 for ; Sat, 08 Feb 2020 12:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scylladb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aPEhtSCbtY8BZtoIZW5xjEM12+SwZtmNjXeBcPgnX/0=; b=d2+WG0L3Ua+ZfkRRRmwWgYDO7uAAiTyxoz0a+ellD2qwRqLxPp66qLB2Zm3ROcA64F ESWa8GGxIEGcehCQfk5xW5Cd11fGq3vz2xho1Pn0na/HWq39G+zUPuzn+m/1E2fmMzL+ fgi9hN1M0mEajFczagZWlLlhGLUwK7UbNH/6o1KXnGvuGoQ5vwaskRaPqP9ggSY2LZET l1XzJmH9SsJ2HYCCQ7hhfFVh+SBvNuQVSML3V48qEj8hxH/qlxCcunD/3bd6Sf0AAdKH weyOwSk7Khue+SEU5T/hwdhrvvZ73EFqb/dbe+z2UEdhnMowQHAOKYALkZQ036XMZXe3 GH6w== 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=aPEhtSCbtY8BZtoIZW5xjEM12+SwZtmNjXeBcPgnX/0=; b=NteCTtDd60N9fH6ZLhaYemoCkzV5iH6xZ4R/U/JzPzfKPUanT4r4PqqE63fbsPqe/s UH9AEYd14h/PZkeahhVeeT9WgvoWvat48ENHk0F64rWD43X7J8YIUleVc7pg5+JskkXJ D4bkncGYh8ie5TBjkrP5wgUnfFCGlzvGwOoZr3ynVx6TCa92qbGAnKxby7l87U1iKXUQ DJRAx6UjMAJHgW1XA+B2nF8+04VJuLVG2Hi8ZbT14m1NcoBcaVkdg28cG6qQCjOqAzbl 94fbq74xhv3YY49JnQ9xMyfTe96CF9O8KNXVtR7aDn98hRC6tw3kPuZhh9HANvcTd6/t Yqhg== X-Gm-Message-State: APjAAAUQZdljpeHLw4DtCb2w45kdB4cIPq55pfTTUGY5A7kmsvWYHnZ1 9vCCJA/0Fkb1KWkUXryCfJ2QTpWzLLQ2TLHA7LlsFg== X-Google-Smtp-Source: APXvYqymJTXzHHgkiFj2Rob/16SUtbMNyhcxK9X5v8F+ZfDUII4odBxjObTLB0xO4vEyd8wcjALQL0gCDrAgrZEiziQ= X-Received: by 2002:a19:9d5:: with SMTP id 204mr2594298lfj.120.1581194628336; Sat, 08 Feb 2020 12:43:48 -0800 (PST) MIME-Version: 1.0 References: <9ec6cbf7-0f0b-f777-8507-199e8837df94@scylladb.com> In-Reply-To: From: Glauber Costa Date: Sat, 8 Feb 2020 15:43:37 -0500 Message-ID: Subject: Re: shutdown not affecting connection? To: Avi Kivity Cc: Pavel Begunkov , io-uring@vger.kernel.org, Jens Axboe Content-Type: text/plain; charset="UTF-8" Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On Sat, Feb 8, 2020 at 3:29 PM Avi Kivity wrote: > > On 2/8/20 10:20 PM, Glauber Costa wrote: > >> > >>> Perhaps you can reduce the > >>> problem to a small C reproducer? > >>> > >> That was my intended next step, yes > > s***, I didn't resist and I had to explain to my wife that no, I don't > > like io_uring more than I like her. > > > > But here it is. > > > > This is a modification of test/connect.c. > > I added a pthread comparison example that should achieve the same > > sequence of events: > > - try to sync connect > > - wait a bit > > - shutdown > > > > I added a fixed wait for pthread to make sure that shutdown is not > > called before connect. > > > > For io_uring, the shutdown is configurable with the program argument. > > This works just fine if I sleep before shutdown (as I would expect from a race). > > This hangs every time if I don't. > > > > Unless I am missing something I don't think this is the expected behavior > > > I think it is understandable. Since the socket is blocking uring moves > the work to a workqueue, and the shutdown() happens before the workqueue > has had a chance to process the connection attempt. So we'll have to > cancel the sqe. It does seem to me that this implies that every shutdown must imply a cancel to a connection. >From the user's perspective, this still feels like a bug to me: the fact that we had to move this to a work queue is an implementation detail: 1) we asked the kernel to do something 2) the kernel returned 3) we called shutdown() to expecting that cancel to go away and never returned. If cancel-after-connect to avoid these races is the intended behavior, it would be nice to get this documented somehow in the io_uring fantastic documentation. In hindsight, cancel-on-shutdown is quite obvious and natural. But I just spent two days to make this obvious and natural. > > > Jens, does the blocking connect doesn't consume a kernel thread while > it's waiting for a connection? Or does it just set things up and move on? >