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] [PATCH 1/3] netbox: allow to create a netbox connection from existing socket
Date: Fri, 23 Mar 2018 13:01:45 +0300	[thread overview]
Message-ID: <E2C340B8-6734-4EB0-B0A4-4A1227217A77@tarantool.org> (raw)
In-Reply-To: <9D9CC51C-2CFA-4B34-BDC6-2E82A7724E16@tarantool.org>

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 = {
         -- @retval     nil Error.
         --
         write = 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 = self._socket:recv(1)
+                local rc = self._socket:read({chunk = 1})
                 if not rc or rc == '' 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 = self.buffer..rc
+                    assert(#rc == 1)
+                    -- Make the char be unread.
+                    self._socket.rbuf.wpos = self._socket.rbuf.wpos - 1
                 end
             end
             return self._socket:send(text)
@@ -120,8 +119,6 @@ local text_connection_mt = {
         read = function(self)
             local ret = self._socket:read(YAML_TERM)
             if ret and ret ~= '' then
-                ret = (self.buffer or '')..ret
-                self.buffer = nil
                 return ret
             end
         end,
@@ -168,7 +165,6 @@ local function wrap_text_socket(connection, url)
         state = 'active',
         host = url.host or 'localhost',
         port = url.service,
-        buffer = nil,
     }, text_connection_mt)
     if not conn:write('require("console").delimiter("$EOF$")\n') or
        not conn:read() then

  reply	other threads:[~2018-03-23 10:01 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       ` [tarantool-patches] " v.shpilevoy
2018-03-23 10:01         ` v.shpilevoy [this message]
2018-03-26 21:55       ` [tarantool-patches] " 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=E2C340B8-6734-4EB0-B0A4-4A1227217A77@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] [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