From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2102.outbound.protection.outlook.com [40.107.220.102]) by sourceware.org (Postfix) with ESMTPS id 8BA593894431 for ; Tue, 27 Apr 2021 15:47:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8BA593894431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cornell.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kbrown@cornell.edu ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aTn4Nw+g2TTPL/mo2voqomT9IIe38oDSkNVq6IMnClLYLvDwdVweCs8kCvORU7jOF4LjEUER0fhpuGTmmTJlMI8XBzRvLquKcjYpvDr2U2sHipQkjaWa0DXzEOVLDv8eX6zKrtlR57F4aNAJLe3px7aAHNl+52doKQHIrSPmoQBm2ZK4r7/SG4Eu2BewbMn21xBGpC/0cW96pZtTAU20CM734V7cJSreee9EVxEjl8yz0qsPUkktiL3hi9GBx+w3JA+kpiPlALfYOkVX22Zi6ZyM1VS+t2AyylLYnznfqAKYdHRMXSxqiHuQ18FMQESewhVU9fWUeaT+A7OL9xaEPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n/3PRcDQiV1izPY3zjNg5K4mlORiZ2hbumkRQfUJ7mg=; b=EEcj3KxK4s3ou4T+UP+ONEpTjmRpEDnjvVVNycWhB6LSvEYItmkdAVG+JA2gzTau6u1r7I96+BVrT4ykSY+ho4z4JIsYf7nMXAvLiLabn834YqRbNkTlR5Ax44AT04BF3wb5YTkQ5atVuPSbuMlr3LJEk9wi61vk5DCA8LO39CGQ7ULWwolHwTmfYMQKTfr/RN+E8yNARMlcTvCZ/u0FaDKlw0BhSuknxD2akfk0tdBUuOEuqROL2+ZkiFm4+dZgm2kcn1jhQBRj84ZOoQhti1VMLJ0UrkkR8Mb0ysfu2pxbInW0pD9vuf3b6i1M3KeYgCXCaH6jW/jY9yW/FgHVLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornell.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n/3PRcDQiV1izPY3zjNg5K4mlORiZ2hbumkRQfUJ7mg=; b=BYLRrb6K77TipQSroXSjzewNUg0zbkw0X4000wXRM+1oXUfBStjzTd7JvAkeVSmUMLRr4Ek+niIWCO7hlUKHTrJuH3lO0fUJSdRYerYXoYhGP2nKuuYBFKjjXNX2sPDc/b8LeJr+AtD88VsnFUVCoIJsG0mmKYEZnOqM6FvtKQ8= Authentication-Results: cygwin.com; dkim=none (message not signed) header.d=none;cygwin.com; dmarc=none action=none header.from=cornell.edu; Received: from BN7PR04MB4388.namprd04.prod.outlook.com (2603:10b6:406:f8::19) by BN6PR04MB0354.namprd04.prod.outlook.com (2603:10b6:404:99::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.25; Tue, 27 Apr 2021 15:47:36 +0000 Received: from BN7PR04MB4388.namprd04.prod.outlook.com ([fe80::59f8:fcc4:f07e:9a89]) by BN7PR04MB4388.namprd04.prod.outlook.com ([fe80::59f8:fcc4:f07e:9a89%4]) with mapi id 15.20.4065.027; Tue, 27 Apr 2021 15:47:36 +0000 To: cygwin-devel From: Ken Brown Subject: The unreliability of AF_UNIX datagram sockets Message-ID: <58da34ac-f2b6-d8b2-e872-834cfcb1ab51@cornell.edu> Date: Tue, 27 Apr 2021 11:47:34 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 Content-Type: multipart/mixed; boundary="------------4613518D903F8339EB0EA7B1" Content-Language: en-US X-Originating-IP: [65.112.130.200] X-ClientProxiedBy: MN2PR20CA0048.namprd20.prod.outlook.com (2603:10b6:208:235::17) To BN7PR04MB4388.namprd04.prod.outlook.com (2603:10b6:406:f8::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [10.13.22.8] (65.112.130.200) by MN2PR20CA0048.namprd20.prod.outlook.com (2603:10b6:208:235::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Tue, 27 Apr 2021 15:47:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1bee76e1-bf8c-45b3-0d65-08d90993c747 X-MS-TrafficTypeDiagnostic: BN6PR04MB0354: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1284; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +TWHChGCEBUZ3dhZWSVG5d5YRFbQtjsI2Fs7aCNtawjE8gjcT8ZUOn9/xtHh4gYFOPLCVMi5KKHROsFz3ZiJYmH3j2iopgfRKzsEJdDdoJ0YeFyoI8JMsZ6N5y2K25WdPQ6fCamva/HQit5mi1D1wMIPOKyvW0MsNfU6QxbNFEyyN5DyaGtejCYzNkk0u6Pqo3/bYwNkXVap5u8Hq8ptPDNrSUjB1mP6OJBlDXtkbKa4wOoIGVlvKIKBwkZ+ke9BZKDJU6tr2eBlgsWF0lzcubWeP0cTCcGRjSbLBu3nqB8mksUj9mOmo/QR+evLfdpqAL3TGmy5fAP//4m2VsTI/siqN5NkEKQWh+X4mufQ2lgE4c9JYIY08cC2AxeK4G1YlDBABAnVfyg6PemIqaWQxNXJ7IsP9daBSO445Qi+GTmB1iTETxT/WLIXAFm9VOYkbBdjqRDCx9X+EcIn1fkBh53MovRU4Y10JnOztLPCi9oZlYmYF/X4ruvlEEc+0lwKsx+xjfcSi8n5ztW1GKlZybywxP53kFBvvBQOEnVJbHJBFG4OsDtJjlTpzx/n5BmUrWaneg7LIj9RZ3T2ISUOHpp1/APdwcgEevhifavYAwWcRDiFR5s+7ne69iZKdHt/EsIAGfTCY6DwF4eOmLv5fkGLkbQublHsbBwRA+sEEJj1UBuEhJKWETI69Z5Enu3tuxCa4yEdr5+Ocr3Esdi9LDFiPu9ncxuKqGqOAAJwHQLHllnVp1Ip5TvubdxMC07lJnQOYS3ZbnbPvQz4vyXQRxo0VjoMtlWjP9+l6zRZl2M= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN7PR04MB4388.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(376002)(366004)(346002)(136003)(786003)(2906002)(83380400001)(6916009)(316002)(2616005)(478600001)(75432002)(31686004)(16526019)(52116002)(6486002)(33964004)(16576012)(966005)(66946007)(235185007)(38100700002)(26005)(66616009)(66556008)(5660300002)(36756003)(8936002)(8676002)(31696002)(186003)(66476007)(956004)(38350700002)(86362001)(43740500002)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?Windows-1252?Q?zlV+AFnZj/3p8ldb762GwX46H0KdEdh+UlQxc5Wqh/ky80L8jrH1XvdT?= =?Windows-1252?Q?j2ctjnBSJvjCSg0GBIyKHoeWB9po1gmS9B6Dq5LHjE+XNwbos+4HjmoR?= =?Windows-1252?Q?pqsmt568oNOLtGabrvcLLPRfUii6CSWvVyGIOgxgFH9J6Xfv99FUV/d9?= =?Windows-1252?Q?TYNddTDN5rc+Xtik4U2VGa3f2ZkXMhymDgKgI+v9Nflmxw7mpCRK7Yqy?= =?Windows-1252?Q?VEQzrWAE3v4UlZ6zGlCCRegHZoK+IS3Ubek2ikW8mmXlsRKCveD1ADKN?= =?Windows-1252?Q?860NTDQshiwJyJCUeDMoN1sM7+DffGJDCVFYiI2Nz1+cxXZ2fPijwb0D?= =?Windows-1252?Q?SnYGpfxv3qOFXATBIWswRqT0glFNf+lh3YjbX4rokZJekmTbHgWsEYQz?= =?Windows-1252?Q?qB3PToBqmZimlb7wV961xuYi6ljSsOx+7sm/alxt5j+0vlKb/Guesjfa?= =?Windows-1252?Q?/jTmd8+RtpnlXFa7TRUOHyoTn1JenB7gXghXs0TI+vzMR/zR9dRylMCu?= =?Windows-1252?Q?vPblrocQ4rh9b1zUBVLzvBNNz36bhVe5TYdONm7Kcgc1O+DIpOVl0uCN?= =?Windows-1252?Q?jOuCHWnbm6syrxQrc+58E32Mjb8IGzB1qFnK1T7zhp7sTChf3l1t6GeF?= =?Windows-1252?Q?PGo1lpc6bofiXqqUay8yQp7gvGCklqNhryBamgwEdtIp3bK/q7XDKxwB?= =?Windows-1252?Q?QGH28v3v2EDvO4pUCWgtBZHt0RamigDpzPFnAds/TKPgg+rRSnQp+FHP?= =?Windows-1252?Q?Aa5xjsOICEOQZu7Yppu04cJe+Dvukj1Wt0jRptKqhSKMl1uHVPa86wYD?= =?Windows-1252?Q?WQK62I7FcsF9PYRVoPQ+nYWpgTT4BV1IYly0+InDJQKpDqd0PvShiFrS?= =?Windows-1252?Q?ZRF2ovTLrMGSrVB64LtjyC8lXRPvHK8Ahy7FpG6Oe1Kegmn1wlIqoF0H?= =?Windows-1252?Q?6LQ/Zw/JKiKD1gY8szROZHtWVufp89PiUWEMfy+iWnMpc+m/kR0HWUZ9?= =?Windows-1252?Q?iiq36ZOpfS6y0v9p5RXSFfm78LBl9V4OgzGl1bb719im/pHXM0WfRXVU?= =?Windows-1252?Q?F0RkzAvwv3GVB9LaPrPp7Hd60AptVEj+dj2fzfV/9orvpWAZH15fiuw+?= =?Windows-1252?Q?2e2ThEtxvcbef2bhv7wkSCgroVQcSbetSipXtr8ySwQqXtBfQ04NsBUj?= =?Windows-1252?Q?/xx+ssJPw8PqSlgGrqetBhwdI40ZoPdd1//xS8o9uijOMtjW9wilIrA+?= =?Windows-1252?Q?hCunhpKHTFpF3ISSKBJZypY0Qw7RNe5y+qeJDkLHfmLPV7JyqKT6uusQ?= =?Windows-1252?Q?A93BEdyWnQ/7nCodtuvQf+Tf7okILmHFK9PXrpN7SrjXAB+rMGgYT0dM?= =?Windows-1252?Q?Z/RujV4BUETfDiuXlKfy1DJDHoTdtfCmUrqteYk2eLxuA3ybBJVrxKXm?= X-OriginatorOrg: cornell.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 1bee76e1-bf8c-45b3-0d65-08d90993c747 X-MS-Exchange-CrossTenant-AuthSource: BN7PR04MB4388.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2021 15:47:35.9359 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4E0xBlkNWMgf9oFexdbSBlPgvbglKXA+tMf1iihce2r+rTInU+D5qVYdTYry7xitqwT42A88ZKuUDza71Y9q1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR04MB0354 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, JMQ_SPF_NEUTRAL, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 15:47:40 -0000 --------------4613518D903F8339EB0EA7B1 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit This is a follow-up to https://cygwin.com/pipermail/cygwin/2021-April/248383.html I'm attaching a test case slightly simpler than the one posted by the OP in that thread. This is a client/server scenario, with non-blocking AF_UNIX datagram sockets. The client writes COUNT messages while the server is playing with his toes. Then the server reads the messages. If COUNT is too big, the expectation is that the client's sendto call will eventually return EAGAIN. This is what happens on Linux. On Cygwin, however, there is never a sendto error; the program ends when recv fails with EAGAIN, indicating that some messages were dropped. I think what's happening is that WSASendTo is silently dropping messages without returning an error. I guess this is acceptable because of the documented unreliability of AF_INET datagram sockets. But AF_UNIX datagram sockets are supposed to be reliable. I can't think of anything that Cygwin can do about this (but I would love to be proven wrong). My real reason for raising the issue is that, as we recently discussed in a different thread, maybe it's time for Cygwin to start using native Windows AF_UNIX sockets. But then we would still have to come up with our own implementation of AF_UNIX datagram sockets, and it seems that we can't simply use the current implementation. AFAICT, Mark's suggestion of using message queues is the best idea so far. I'm willing to start working on the switch to native AF_UNIX sockets. (I'm frankly getting bored with working on the pipe implementation, and this doesn't really seem like it has much of a future.) But I'd like to be confident that there's a good solution to the datagram problem before I invest too much time in this. Ken --------------4613518D903F8339EB0EA7B1 Content-Type: text/plain; charset=UTF-8; name="dgram_loss.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dgram_loss.c" #include #include #include #include #include #include #include #include #define SOCK_PATH "/tmp/mysocket" int sfd; int server () { struct sockaddr_un un; if (unlink (SOCK_PATH) < 0 && errno != ENOENT) { printf ("unlink: %d <%s>\n", errno, strerror (errno)); return -1; } sfd = socket (AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0); if (sfd < 0) { printf ("SRV socket: %d <%s>\n", errno, strerror (errno)); return -1; } memset (&un, 0, sizeof un); un.sun_family = AF_UNIX; strcpy (un.sun_path, SOCK_PATH); if (bind (sfd, (const struct sockaddr *) &un, sizeof un) < 0) { printf ("SRV bind: %d <%s>\n", errno, strerror (errno)); return -1; } return 0; } int main () { int fd; struct sockaddr_un un; fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0); if (fd < 0) { printf ("socket: %d <%s>\n", errno, strerror (errno)); return 1; } if (server ()) return 2; memset (&un, 0, sizeof un); un.sun_family = AF_UNIX; strcpy (un.sun_path, SOCK_PATH); #define COUNT 64 * 1024 for (int i = 0; i < COUNT; i++) { if (sendto (fd, &i, sizeof i, 0, (struct sockaddr *) &un, sizeof un) != sizeof i) { printf ("sendto: %d <%s>, i = %d\n", errno, strerror (errno), i); return 3; } } for (int i = 0; i < COUNT; i++) { int j = -1; ssize_t nr = recv (sfd, &j, sizeof j, 0); if (nr < 0) { printf ("recv: %d <%s>, i = %d\n", errno, strerror (errno), i); return 4; } if (nr != sizeof j) { printf ("partial read, i = %d\n", i); return 5; } if (i != j) printf ("i = %d, j = %d\n", i, j); } } --------------4613518D903F8339EB0EA7B1--