From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 13CC86EC56; Sat, 20 Mar 2021 00:46:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 13CC86EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616190365; bh=Gnb0E51IfsawXaxcqAukerWR+7ZZ1hIVee5JVPfVAe8=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CS9UqnTDEm5RPFrs+S0B2vd11/LaluoKGV0sRXhCKJ9hMKCLezicJYcDpE6zMWCbW e+8mDBXHIU2F6Zm6xMA112aOMFDON/CzPvPiq9d2kU0dZyKyb9k+/nyr59b7RvG5rL LzrqzwpPW/ppJxdxKYq89nnofsW8SWWwv++tX6Xs= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 470266EC56 for ; Sat, 20 Mar 2021 00:46:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 470266EC56 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lNMwV-0003ap-BA; Sat, 20 Mar 2021 00:46:03 +0300 To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org References: Message-ID: <6a67a875-7947-fa9b-5439-92e34c202cf7@tarantool.org> Date: Fri, 19 Mar 2021 22:46:02 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F179C48A9DDACBFB6F5347129BC2C9341C182A05F538085040E487245D8D2A33F0CF91EDEB3A6720468601844F6846937420D09754039BD131 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DB84ED444C624799EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748D05F5E01EE6C998638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C81A23F326053F827AD524FDA6DBC45BB6965C592852EF125A471835C12D1D9774AD6D5ED66289B5259CC434672EE6371117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658359CC434672EE6371117882F4460429728AD0CFFFB425014E868A13BD56FB6657A7F4EDE966BC389F9E8FC8737B5C2249F7FD1A3A8AE6177F089D37D7C0E48F6CCF19DD082D7633A0E7DDDDC251EA7DABAAAE862A0553A39223F8577A6DFFEA7C4CB6D4FEBB558B5443847C11F186F3C5E7DDDDC251EA7DABCC89B49CDF41148F6B16E133A9586FB82623479134186CDE6BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2BBE337FB72E923155C0AF1600DCBC20BD52826C51A2876ABDB810548DA3D36E5 X-C1DE0DAB: 0D63561A33F958A5E4D9778395D73A7D3A15E391527E7A6F9E0BBB0B7CA16522D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75F04B387B5D7535DE410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343536C6A4332D8B8AF68E321B10C74E0C59082106D574E9F751DF14657B9F4AC0C3164C29C495F98E1D7E09C32AA3244C07FA4D17D1D2256AC654F603A00F91A3A90944CA99CF22E3729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyKyJYJ15DtJS7qBnPdw9Mg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822BE306D9302D53E16E829A22F3F4732F93841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 1/2] swim: add SO_BROADCAST option X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 19.03.2021 07:53, Cyrill Gorcunov via Tarantool-patches wrote: > On Fri, Mar 19, 2021 at 12:18:46AM +0100, Vladislav Shpilevoy wrote: >> I force updated the patch on the branch. >> >> Could you please check if it works on your machine? For >> example, this test: >> >> uuid = require('uuid') >> swim = require('swim') >> >> s = swim.new({uuid = uuid(), uri = '127.0.0.1:3313'}) >> >> s:broadcast(3313) >> >> On Mac it used to print EADDRNOTAVAIL message. Probably >> would fail with something on Linux too, but I don't know. >> Might just work fine as well. > > Ack. Thanks! FWIW on linux this fails with > | tarantool> SystemError sendto(177), called on fd 10, aka 127.0.0.1:3313: Invalid argument I made the error not critical on Linux so it is ignored now. The new patch: ==================== swim: add SO_BROADCAST option Swim node couldn't talk to broadcast network interfaces because the option SO_BROADCAST wasn't set. It worked fine for localhost broadcast, but failed for all the other IPs. There is no a test, because the tests work for the localhost only anyway. It still fails on Mac though in case the swim node was bound to 127.0.0.1. Then somewhy sendto() raises EADDRNOTAVAIL on attempt to broadcast beyond the local machine. It happens on Linux too, but with EINVAL error. These errors are ignored because are not critical. Part of #5864 diff --git a/src/lib/swim/swim_io.c b/src/lib/swim/swim_io.c index c8558c43e..0002472fa 100644 --- a/src/lib/swim/swim_io.c +++ b/src/lib/swim/swim_io.c @@ -512,8 +512,26 @@ static inline void swim_complete_send(struct swim_scheduler *scheduler, struct swim_task *task, ssize_t size) { - if (size < 0) - diag_log(); + if (size < 0) { + bool is_critical = true; + int err = diag_last_error(diag_get())->saved_errno; +#if TARGET_OS_DARWIN + /* + * On Mac this error happens regularly if SWIM is bound to + * the localhost and tries to broadcast out of the machine. This + * is not critical, because will happen in the tests a lot, and + * in prod it simply should not bind to localhost if there are + * multiple machines in the cluster. Besides, Mac as a platform + * is not supposed to be used in prod. + */ + is_critical = (err != EADDRNOTAVAIL); +#else + /* The same as EADDRNOTAVAIL, but happens on Linux as EINVAL. */ + is_critical = (err != EINVAL); +#endif + if (is_critical) + diag_log(); + } if (task->complete != NULL) task->complete(task, scheduler, size); } diff --git a/src/lib/swim/swim_transport_udp.c b/src/lib/swim/swim_transport_udp.c index c0317a20b..12626cc49 100644 --- a/src/lib/swim/swim_transport_udp.c +++ b/src/lib/swim/swim_transport_udp.c @@ -80,25 +80,27 @@ swim_transport_bind(struct swim_transport *transport, return 0; } + int is_on = 1; + int real_port = new_addr->sin_port; int fd = sio_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) return -1; - if (sio_bind(fd, (struct sockaddr *) addr, addr_len) != 0 || - evio_setsockopt_server(fd, AF_INET, SOCK_DGRAM) != 0) { + if (sio_bind(fd, (struct sockaddr *) addr, addr_len) != 0) { if (errno == EADDRINUSE) diag_set(SocketError, sio_socketname(fd), "bind"); - close(fd); - return -1; + goto end_error; } - int real_port = new_addr->sin_port; + if (sio_setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &is_on, + sizeof(is_on)) != 0) + goto end_error; + if (evio_setsockopt_server(fd, AF_INET, SOCK_DGRAM) != 0) + goto end_error; if (is_new_port_any) { struct sockaddr_in real_addr; addr_len = sizeof(real_addr); if (sio_getsockname(fd, (struct sockaddr *) &real_addr, - &addr_len) != 0) { - close(fd); - return -1; - } + &addr_len) != 0) + goto end_error; real_port = real_addr.sin_port; } if (transport->fd != -1) @@ -107,6 +109,9 @@ swim_transport_bind(struct swim_transport *transport, transport->addr = *new_addr; transport->addr.sin_port = real_port; return 0; +end_error: + close(fd); + return -1; } void