[tarantool-patches] [PATCH 3/3] box/lua/console: Verify remote protocol for compatibility

Cyrill Gorcunov gorcunov at gmail.com
Fri Jul 12 22:04:38 MSK 2019


New versions of tarantool use binary protocol to negotiate
with remote servers where all data can be properly serialized
by the serpent engine.

In turn old instances continue shipping yaml encoded data via
text protocol which we simply can't map into lua form. Thus
when we connect to a peer make sure that the data it will
provide us is supported.

Part-of #3834
---
 src/box/lua/console.lua | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 7c3b608cb..a9ff6f9a7 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -87,6 +87,22 @@ local function output_save(fmt, opts)
     }
 end
 
+local function output_verify_remote(greeting)
+    --
+    -- In case if remote peer is operating over
+    -- old yaml protocol we are unable to decode
+    -- it to non-yaml serializers.
+    if greeting.protocol == 'Lua console' then
+        local d = box.session.storage.console_output
+        if d ~= nil and d["fmt"] == "lua" then
+            local msg1 = "Peer uses deprecated '%s' protocol. "
+            local msg2 = "Switch output to 'yaml' format to proceed."
+            return false, msg1:format(greeting.protocol) .. msg2
+        end
+    end
+    return true, nil
+end
+
 local function format(status, ...)
     local d = box.session.storage.console_output
     --
@@ -572,6 +588,14 @@ local function connect(uri, opts)
         log.verbose(greeting)
         box.error(box.error.NO_CONNECTION)
     end
+
+    local ok, res = output_verify_remote(greeting)
+    if not ok then
+        connection:close()
+        pcall(self.on_client_disconnect, self)
+        error(res)
+    end
+
     local remote
     if greeting.protocol == 'Lua console' then
         remote = wrap_text_socket(connection, u,
-- 
2.20.1





More information about the Tarantool-patches mailing list