From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: [tarantool-patches] Re: [PATCH 1/3] netbox: allow to create a netbox connection from existing socket From: "v.shpilevoy@tarantool.org" In-Reply-To: <9C4A63BA-42EB-4EB6-A19C-39102FED2F0F@tarantool.org> Date: Thu, 22 Mar 2018 22:57:34 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <9D9CC51C-2CFA-4B34-BDC6-2E82A7724E16@tarantool.org> References: <10c500ef97902f645111fd2d46e756bf8dfdac1d.1521745741.git.v.shpilevoy@tarantool.org> <20180322193312.GA18129@atlas> <9C4A63BA-42EB-4EB6-A19C-39102FED2F0F@tarantool.org> To: tarantool-patches@freelists.org Cc: Konstantin Osipov , vdavydov.dev@gmail.com List-ID: 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 =3D select('#', ...) > if count =3D=3D 0 then > - return "---"..YAML_TERM > + return "---\n...\n" > end > local res =3D {} > for i=3D1,count,1 do > @@ -424,7 +424,7 @@ local function connect(uri, opts) > if greeting.protocol =3D=3D 'Lua console' then > remote =3D wrap_text_socket(connection, u) > else > - remote =3D net_box.wrap_socket(connection, greeting, u) > + remote =3D net_box.wrap(connection, greeting, u) > if not remote.host then > remote.host =3D '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 =3D fiber.clock(), = callback('fetch_connect_timeout') > if existing_connection then > connection =3D existing_connection > + -- Nullify the connection - on reconnect it must not > + -- be get again. > existing_connection =3D nil > assert(greeting) > assert(greeting.protocol ~=3D 'Lua console') > @@ -627,7 +629,7 @@ local console_mt =3D { > =20 > local space_metatable, index_metatable > =20 > -local function do_connect(host, port, opts, existing_connection, = greeting) > +local function connect_impl(host, port, opts, existing_connection, = greeting) > local user, password =3D opts.user, opts.password; opts.password = =3D nil > local last_reconnect_error > local remote =3D {host =3D host, port =3D port, opts =3D opts, = state =3D 'initial'} > @@ -707,12 +709,12 @@ end > =20 > local function connect(...) > local host, port, opts =3D parse_connect_params(...) > - return do_connect(host, port, opts) > + return connect_impl(host, port, opts) > end > =20 > -local function wrap_socket(connection, greeting, url, opts) > +local function wrap(connection, greeting, url, opts) > if connection =3D=3D nil or type(greeting) ~=3D 'table' then > - error('Usage: netbox.wrap_socket(socket, greeting, [opts])') > + error('Usage: netbox.wrap(socket, greeting, [opts])') > end > if greeting.protocol =3D=3D '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 =3D 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 > =20 > local function check_remote_arg(remote, method) > @@ -1151,7 +1153,7 @@ local this_module =3D { > connect =3D connect, > new =3D connect, -- Tarantool < 1.7.1 compatibility, > decode_greeting =3D internal.decode_greeting, > - wrap_socket =3D wrap_socket, > + wrap =3D wrap, > } > =20 > 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 =3D s:read({chunk =3D 128}) > greeting =3D net.decode_greeting(greeting) > --- > ... > -c =3D net.wrap_socket(s, greeting, uri) > +c =3D net.wrap(s, greeting, uri, {reconnect_after =3D 0.01}) > --- > ... > c.state > @@ -2362,6 +2362,23 @@ c.space.test:delete{1} > --- > - [1] > ... > +-- > +-- Break a connection to test reconnect_after. > +-- > +_ =3D 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 =3D urilib.parse(tostring(box.cfg.listen)) > s =3D socket.tcp_connect(uri.host, uri.service) > greeting =3D s:read({chunk =3D 128}) > greeting =3D net.decode_greeting(greeting) > -c =3D net.wrap_socket(s, greeting, uri) > +c =3D net.wrap(s, greeting, uri, {reconnect_after =3D 0.01}) > c.state > =20 > a =3D 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. > +-- > +_ =3D 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 >=20 >=20