Tarantool development patches archive
 help / color / mirror / Atom feed
From: "v.shpilevoy@tarantool.org" <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Konstantin Osipov <kostja@tarantool.org>, vdavydov.dev@gmail.com
Subject: Re: [tarantool-patches] Re: [PATCH 1/3] netbox: allow to create a netbox connection from existing socket
Date: Thu, 22 Mar 2018 22:57:34 +0300	[thread overview]
Message-ID: <9D9CC51C-2CFA-4B34-BDC6-2E82A7724E16@tarantool.org> (raw)
In-Reply-To: <9C4A63BA-42EB-4EB6-A19C-39102FED2F0F@tarantool.org>

All is fixed on branch. Here is the diff for fixes.

> diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
> index 2109c2fa0..02e7f1066 100644
> --- a/src/box/lua/console.lua
> +++ b/src/box/lua/console.lua
> @@ -32,7 +32,7 @@ local function format(status, ...)
>      if status then
>          local count = select('#', ...)
>          if count == 0 then
> -            return "---"..YAML_TERM
> +            return "---\n...\n"
>          end
>          local res = {}
>          for i=1,count,1 do
> @@ -424,7 +424,7 @@ local function connect(uri, opts)
>      if greeting.protocol == 'Lua console' then
>          remote = wrap_text_socket(connection, u)
>      else
> -        remote = net_box.wrap_socket(connection, greeting, u)
> +        remote = net_box.wrap(connection, greeting, u)
>          if not remote.host then
>              remote.host = 'localhost'
>          end
> diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
> index cf1a04237..57e2f1b17 100644
> --- a/src/box/lua/net_box.lua
> +++ b/src/box/lua/net_box.lua
> @@ -373,6 +373,8 @@ local function create_transport(host, port, user, password, callback,
>          local tm_begin, tm = fiber.clock(), callback('fetch_connect_timeout')
>          if existing_connection then
>              connection = existing_connection
> +            -- Nullify the connection - on reconnect it must not
> +            -- be get again.
>              existing_connection = nil
>              assert(greeting)
>              assert(greeting.protocol ~= 'Lua console')
> @@ -627,7 +629,7 @@ local console_mt = {
>  
>  local space_metatable, index_metatable
>  
> -local function do_connect(host, port, opts, existing_connection, greeting)
> +local function connect_impl(host, port, opts, existing_connection, greeting)
>      local user, password = opts.user, opts.password; opts.password = nil
>      local last_reconnect_error
>      local remote = {host = host, port = port, opts = opts, state = 'initial'}
> @@ -707,12 +709,12 @@ end
>  
>  local function connect(...)
>      local host, port, opts = parse_connect_params(...)
> -    return do_connect(host, port, opts)
> +    return connect_impl(host, port, opts)
>  end
>  
> -local function wrap_socket(connection, greeting, url, opts)
> +local function wrap(connection, greeting, url, opts)
>      if connection == nil or type(greeting) ~= 'table' then
> -        error('Usage: netbox.wrap_socket(socket, greeting, [opts])')
> +        error('Usage: netbox.wrap(socket, greeting, [opts])')
>      end
>      if greeting.protocol == 'Lua console' then
>          error('Can not wrap console socket')
> @@ -721,7 +723,7 @@ local function wrap_socket(connection, greeting, url, opts)
>      if not opts.user and not opts.password then
>          opts.user, opts.password = url.login, url.password
>      end
> -    return do_connect(url.host, url.service, opts, connection, greeting)
> +    return connect_impl(url.host, url.service, opts, connection, greeting)
>  end
>  
>  local function check_remote_arg(remote, method)
> @@ -1151,7 +1153,7 @@ local this_module = {
>      connect = connect,
>      new = connect, -- Tarantool < 1.7.1 compatibility,
>      decode_greeting = internal.decode_greeting,
> -    wrap_socket = wrap_socket,
> +    wrap = wrap,
>  }
>  
>  function this_module.timeout(timeout, ...)
> diff --git a/test/box/net.box.result b/test/box/net.box.result
> index cb9410085..cbfa0c7a1 100644
> --- a/test/box/net.box.result
> +++ b/test/box/net.box.result
> @@ -2317,7 +2317,7 @@ greeting = s:read({chunk = 128})
>  greeting = net.decode_greeting(greeting)
>  ---
>  ...
> -c = net.wrap_socket(s, greeting, uri)
> +c = net.wrap(s, greeting, uri, {reconnect_after = 0.01})
>  ---
>  ...
>  c.state
> @@ -2362,6 +2362,23 @@ c.space.test:delete{1}
>  ---
>  - [1]
>  ...
> +--
> +-- Break a connection to test reconnect_after.
> +--
> +_ = c._transport.perform_request(nil, nil, 'inject', nil, '\x80')
> +---
> +...
> +c.state
> +---
> +- error_reconnect
> +...
> +while not c:is_connected() do fiber.sleep(0.01) end
> +---
> +...
> +c:ping()
> +---
> +- true
> +...
>  s:drop()
>  ---
>  ...
> diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua
> index 487401514..e0cac1955 100644
> --- a/test/box/net.box.test.lua
> +++ b/test/box/net.box.test.lua
> @@ -950,7 +950,7 @@ uri = urilib.parse(tostring(box.cfg.listen))
>  s = socket.tcp_connect(uri.host, uri.service)
>  greeting = s:read({chunk = 128})
>  greeting = net.decode_greeting(greeting)
> -c = net.wrap_socket(s, greeting, uri)
> +c = net.wrap(s, greeting, uri, {reconnect_after = 0.01})
>  c.state
>  
>  a = 100
> @@ -964,6 +964,14 @@ c:reload_schema()
>  c.space.test:replace{1}
>  c.space.test:get{1}
>  c.space.test:delete{1}
> +--
> +-- Break a connection to test reconnect_after.
> +--
> +_ = c._transport.perform_request(nil, nil, 'inject', nil, '\x80')
> +c.state
> +while not c:is_connected() do fiber.sleep(0.01) end
> +c:ping()
> +
>  s:drop()
>  c:close()
>  c.state
> 
> 

  reply	other threads:[~2018-03-22 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-22 19:17 [PATCH 0/3] console: do not use netbox for console text connections Vladislav Shpilevoy
2018-03-22 19:17 ` [PATCH 1/3] netbox: allow to create a netbox connection from existing socket Vladislav Shpilevoy
2018-03-22 19:33   ` [tarantool-patches] " Konstantin Osipov
2018-03-22 19:50     ` v.shpilevoy
2018-03-22 19:57       ` v.shpilevoy [this message]
2018-03-23 10:01         ` v.shpilevoy
2018-03-26 21:55       ` Konstantin Osipov
2018-03-22 19:17 ` [PATCH 2/3] console: do not use netbox for console text connections Vladislav Shpilevoy
2018-03-22 19:36   ` [tarantool-patches] " Konstantin Osipov
2018-03-22 19:17 ` [PATCH 3/3] netbox: deprecate console support Vladislav Shpilevoy
2018-03-22 19:37   ` [tarantool-patches] " Konstantin Osipov

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=9D9CC51C-2CFA-4B34-BDC6-2E82A7724E16@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] Re: [PATCH 1/3] netbox: allow to create a netbox connection from existing socket' \
    /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