Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [tarantool-patches] [server-dev] Re: Re: [PATCH v2 1/2] lua: return getaddrinfo() errors
Date: Wed, 18 Dec 2019 17:58:53 +0300	[thread overview]
Message-ID: <20191218145852.zvqd7kyuodyzv7cm@tkn_work_nb> (raw)
In-Reply-To: <35E941DB-8252-478B-80C2-592FFAA6011E@tarantool.org>

> >> @@ -1360,9 +1363,12 @@ local function lsocket_tcp_connect(self, host, port)
> >>     -- This function is broken by design
> >>     local ga_opts = { family = 'AF_INET', type = 'SOCK_STREAM' }
> >>     local timeout = deadline - fiber.clock()
> >> -    local dns = getaddrinfo(host, port, timeout, ga_opts)
> >> -    if dns == nil or #dns == 0 then
> >> -        self._errno = boxerrno.EINVAL
> >> +    local dns, err = getaddrinfo(host, port, timeout, ga_opts)
> >> +    if dns == nil then
> >> +        return nil, err
> >> +    end
> >> +    if #dns == 0 then
> >> +        boxerrno(self._errno)
> >>         return nil, socket_error(self)
> >>     end
> >>     for _, remote in ipairs(dns) do
> > 
> > EINVAL here is changed to self._errno, which is always `nil` at least
> > for typical usage of lua socket: `s = socket.tcp()`, then `s:connect()`.
> > 
> > Let's keep the old behaviour (EINVAL) when getaddrinfo() returns zero
> > amount of addresses.
> > 
> > RFC 2553 ('Basic Socket Interface Extensions for IPv6') states:
> > 
> > | Upon successful return a pointer to a linked list of one or more
> > | addrinfo structures is returned through the final argument.
> > 
> > RFC 3493 ('Basic Socket Interface Extensions for IPv6') states the same,
> > but more explicitly:
> > 
> > | Upon successful return of getaddrinfo(), the location to which res
> > | points shall refer to a linked list of addrinfo structures, each of
> > | which shall specify a socket address and information for use in
> > | creating a socket with which to use that socket address.  The list
> > | shall include at least one addrinfo structure.
> > 
> > So this situation should not occur. But anyway we should not miss to set
> > a certain errno in the case at least for consistency with tcp_connect().
> > 
> > Also I think that we should set errno to EINVAL when getaddrinfo() fails
> > to keep the code backward compatible: say, a user lean on this value
> > when tcp_connect() / :connect() returns `nil`.
>
> I understand so:
> 
> diff --git a/src/lua/socket.lua b/src/lua/socket.lua
> index a334ad45b..6c829a11c 100644
> --- a/src/lua/socket.lua
> +++ b/src/lua/socket.lua
> @@ -995,7 +995,13 @@ local function getaddrinfo(host, port, timeout, opts)
>          end
>  
>      end
> -    return internal.getaddrinfo(host, port, timeout, ga_opts)
> +
> +    local ret, err = internal.getaddrinfo(host, port, timeout, ga_opts)
> +    if ret == nil then
> +        boxerrno(boxerrno.EINVAL)
> +        return nil, err
> +    end
> +    return ret
>  end
>  
>  -- tcp connector
> @@ -1041,9 +1047,12 @@ local function tcp_connect(host, port, timeout)
>      end
>      local timeout = timeout or TIMEOUT_INFINITY
>      local stop = fiber.clock() + timeout
> -    local dns = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM',
> +    local dns, err = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM',
>          protocol = 'tcp' })
> -    if dns == nil or #dns == 0 then
> +    if dns == nil then
> +        return nil, err
> +    end
> +    if #dns == 0 then
>          boxerrno(boxerrno.EINVAL)
>          return nil
>      end
> @@ -1360,8 +1369,12 @@ local function lsocket_tcp_connect(self, host, port)
>      -- This function is broken by design
>      local ga_opts = { family = 'AF_INET', type = 'SOCK_STREAM' }
>      local timeout = deadline - fiber.clock()
> -    local dns = getaddrinfo(host, port, timeout, ga_opts)
> -    if dns == nil or #dns == 0 then
> +    local dns, err = getaddrinfo(host, port, timeout, ga_opts)
> +    if dns == nil then
> +        self._errno = boxerrno()
> +        return nil, err
> +    end
> +    if #dns == 0 then
>          self._errno = boxerrno.EINVAL
>          return nil, socket_error(self)
>      end
> @@ -1547,9 +1560,12 @@ local function lsocket_connect(host, port)
>      if host == nil or port == nil then
>          error("Usage: luasocket.connect(host, port)")
>      end
> -    local s = tcp_connect(host, port)
> +    local s, err = tcp_connect(host, port)
>      if not s then
> -        return nil, boxerrno.strerror()
> +        if not err then
> +            return nil, boxerrno.strerror()
> +        end
> +        return nil, err
>      end
>      setmetatable(s, lsocket_tcp_client_mt)
>      return s

I meant that `self._errno = boxerrno.EINVAL` was changed to
`boxerrno(self._errno)` in `#dns == 0` case and it does not more affect
the second return value (an error message). I would return it back for
`#dns == 0` case (only for it).

The motivation is just to don't change things that we don't asked to
change.

I didn't mean changes in getaddrinfo() function itself.

> > Also I see that we don't document Lua Socket part of the API:
> > https://www.tarantool.io/en/doc/1.10/reference/reference_lua/socket/
> 
> Is this the part of this patchset? Maybe, it would be better to do doc
> request separately.

It was in context of your docbot request: there is no need to ask to
update Lua Socket API docs if we does not provide it at all.

Lua Socket has its own API documentation, so it is maybe okay to don't
document it again on our website.

  reply	other threads:[~2019-12-18 14:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-15 16:58 [tarantool-patches] [PATCH] " Roman Khabibov
2019-06-23 20:31 ` [tarantool-patches] " Alexander Turenko
2019-06-25 13:38   ` [tarantool-patches] Re: [PATCH v2 1/2] " Roman Khabibov
2019-07-09  8:04     ` Alexander Turenko
2019-07-10  2:16       ` Roman Khabibov
2019-07-23 12:39         ` Alexander Turenko
2019-07-26 13:48           ` Alexander Turenko
2019-08-05 13:36           ` Roman Khabibov
2019-08-29  0:45             ` Alexander Turenko
     [not found]               ` <868EAF2C-A491-46C9-AD37-7512D6CAB213@tarantool.org>
2019-09-06 13:45                 ` [tarantool-patches] Re: [server-dev] " Alexander Turenko
2019-09-10 12:54                   ` Roman Khabibov
2019-11-01 14:39                     ` [Tarantool-patches] [server-dev] Re: [tarantool-patches] " Alexander Turenko
2019-11-21 17:27                       ` [Tarantool-patches] [tarantool-patches] [server-dev] " Roman Khabibov
2019-12-08 19:48                         ` Alexander Turenko
2019-12-10 16:25                           ` Roman Khabibov
2019-12-18 14:58                             ` Alexander Turenko [this message]
2019-12-21 17:50                               ` Roman Khabibov
2019-12-23 13:36                                 ` Alexander Turenko
2019-12-26 17:29                                   ` Roman Khabibov
2020-02-18 13:55                                     ` [Tarantool-patches] Fwd: " Roman Khabibov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191218145852.zvqd7kyuodyzv7cm@tkn_work_nb \
    --to=alexander.turenko@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [tarantool-patches] [server-dev] Re: Re: [PATCH v2 1/2] lua: return getaddrinfo() errors' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox