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] [PATCH 1/3] netbox: allow to create a netbox connection from existing socket From: "v.shpilevoy@tarantool.org" In-Reply-To: <9D9CC51C-2CFA-4B34-BDC6-2E82A7724E16@tarantool.org> Date: Fri, 23 Mar 2018 13:01:45 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <10c500ef97902f645111fd2d46e756bf8dfdac1d.1521745741.git.v.shpilevoy@tarantool.org> <20180322193312.GA18129@atlas> <9C4A63BA-42EB-4EB6-A19C-39102FED2F0F@tarantool.org> <9D9CC51C-2CFA-4B34-BDC6-2E82A7724E16@tarantool.org> To: tarantool-patches@freelists.org Cc: Konstantin Osipov , vdavydov.dev@gmail.com List-ID: I have found, that SIGPIPE appears only under a debugger (lldb or gdb), = but it does not mean, that it's ok to crash during debugging. I leave = the try-to-read-before-write fix, but I made it slightly more simple. = Instead of storing read symbols in a buffer I just mark them as unread = in ibuf. The patch is below and on the branch. diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 02e7f1066..633144c7f 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -94,20 +94,19 @@ local text_connection_mt =3D { -- @retval nil Error. -- write =3D function(self, text) - -- It is the hack to protect from SIGPIPE on send in + -- It is the hack to protect from SIGPIPE, which is + -- not ignored under debugger (gdb, lldb) on send in -- a socket, that is actually closed. If a socket is -- readable and read() returns nothing then the socket -- is closed, and writing into it will raise SIGPIPE. if self._socket:readable(0) then - local rc =3D self._socket:recv(1) + local rc =3D self._socket:read({chunk =3D 1}) if not rc or rc =3D=3D '' then return nil else - -- But if it was literally readable, the - -- single read byte can not be put back, and - -- must be stored somewhere, until console - -- do read(). - self.buffer =3D self.buffer..rc + assert(#rc =3D=3D 1) + -- Make the char be unread. + self._socket.rbuf.wpos =3D self._socket.rbuf.wpos - = 1 end end return self._socket:send(text) @@ -120,8 +119,6 @@ local text_connection_mt =3D { read =3D function(self) local ret =3D self._socket:read(YAML_TERM) if ret and ret ~=3D '' then - ret =3D (self.buffer or '')..ret - self.buffer =3D nil return ret end end, @@ -168,7 +165,6 @@ local function wrap_text_socket(connection, url) state =3D 'active', host =3D url.host or 'localhost', port =3D url.service, - buffer =3D nil, }, text_connection_mt) if not conn:write('require("console").delimiter("$EOF$")\n') or not conn:read() then