[Tarantool-patches] [PATCH 1/2] swim: add SO_BROADCAST option

Cyrill Gorcunov gorcunov at gmail.com
Thu Mar 18 22:37:51 MSK 2021


On Thu, Mar 18, 2021 at 01:02:03AM +0100, Vladislav Shpilevoy wrote:
> 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. Not present on Linux, where
> such an error simply can't be returned from sendto(). This error
> is ignored on Mac, because it is not critical.
> 
> Part of #5906
> ---
>  src/lib/swim/swim_io.c            | 19 +++++++++++++++++--
>  src/lib/swim/swim_transport_udp.c | 23 ++++++++++++++---------
>  2 files changed, 31 insertions(+), 11 deletions(-)
> 
> diff --git a/src/lib/swim/swim_io.c b/src/lib/swim/swim_io.c
> index c8558c43e..45df36ba4 100644
> --- a/src/lib/swim/swim_io.c
> +++ b/src/lib/swim/swim_io.c
> @@ -512,8 +512,23 @@ 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 = false;
> +#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.
> +		 */
> +		struct error *last = diag_last_error(diag_get());
> +		is_critical = (last->saved_errno == EADDRNOTAVAIL);
> +#endif
> +		if (is_critical)
> +			diag_log();
> +	}
>  	if (task->complete != NULL)
>  		task->complete(task, scheduler, size);

Vlad, I don't understand. For non-mac users this @is_critical will
always be false, maybe we better move the whoe branch to TARGET_OS_DARWIN
then? Ie

	if (size < 0) {
	#if TARGET_OS_DARWIN
		if (is_critical)
			diag_log();
	#endif
	}

or you made it this way to escape unused parameter compiler warning?


More information about the Tarantool-patches mailing list