From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 9C14E469719 for ; Wed, 11 Mar 2020 12:14:01 +0300 (MSK) Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1jBxRB-0003so-6F for tarantool-patches@dev.tarantool.org; Wed, 11 Mar 2020 12:14:01 +0300 From: Chris Sosnin Date: Wed, 11 Mar 2020 12:14:00 +0300 Message-Id: <9547e0b11186786ebbc507536938f2764cb5fe58.1583917262.git.k.sosnin@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v3 2/2] iproto: add an empty body to the unprepare response List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Absence of the body in the unprepare response forces users to perform additional checks to avoid errors. Adding an empty body fixes this problem. Closes #4769 --- src/box/iproto.cc | 19 +++--- .../gh-4769-unprepare-response-body.result | 62 +++++++++++++++++++ .../gh-4769-unprepare-response-body.test.lua | 30 +++++++++ 3 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 test/box/gh-4769-unprepare-response-body.result create mode 100644 test/box/gh-4769-unprepare-response-body.test.lua diff --git a/src/box/iproto.cc b/src/box/iproto.cc index f313af6ae..5a3fb5d0b 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1780,21 +1780,24 @@ tx_process_sql(struct cmsg *m) * become out of date during yield. */ out = msg->connection->tx.p_obuf; + if (is_unprepare) { + if (iproto_reply_ok(out, msg->header.sync, schema_version) != 0) + goto error; + iproto_wpos_create(&msg->wpos, out); + return; + } struct obuf_svp header_svp; /* Prepare memory for the iproto header. */ if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0) { port_destroy(&port); goto error; } - /* Nothing to dump in case of UNPREPARE request. */ - if (!is_unprepare) { - if (port_dump_msgpack(&port, out) != 0) { - port_destroy(&port); - obuf_rollback_to_svp(out, &header_svp); - goto error; - } + if (port_dump_msgpack(&port, out) != 0) { port_destroy(&port); + obuf_rollback_to_svp(out, &header_svp); + goto error; } + port_destroy(&port); iproto_reply_sql(out, &header_svp, msg->header.sync, schema_version); iproto_wpos_create(&msg->wpos, out); return; @@ -1871,7 +1874,7 @@ net_send_msg(struct cmsg *m) } /** - * Complete sending an iproto error: + * Complete sending an iproto error: * recycle the error object and flush output. */ static void diff --git a/test/box/gh-4769-unprepare-response-body.result b/test/box/gh-4769-unprepare-response-body.result new file mode 100644 index 000000000..a5230fad1 --- /dev/null +++ b/test/box/gh-4769-unprepare-response-body.result @@ -0,0 +1,62 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... +test_run:cmd("setopt delimiter ';'") + | --- + | - true + | ... + +net_box = require('net.box') +msgpack = require('msgpack') +urilib = require('uri') + +IPROTO_REQUEST_TYPE = 0x00 +IPROTO_PREPARE = 13 +IPROTO_SQL_TEXT = 0x40 +IPROTO_STMT_ID = 0x43 + +test_run:cmd("setopt delimiter ''"); + | --- + | ... + +box.schema.user.grant('guest', 'read, write, execute', 'universe') + | --- + | ... +uri = urilib.parse(box.cfg.listen) + | --- + | ... +socket = net_box.establish_connection(uri.host, uri.service) + | --- + | ... + +header = { [IPROTO_REQUEST_TYPE] = IPROTO_PREPARE } + | --- + | ... +body = { [IPROTO_SQL_TEXT] = 'SELECT 1' } + | --- + | ... +response = iproto_request(socket, header, body) + | --- + | ... + +body = { [IPROTO_STMT_ID] = response['body'][IPROTO_STMT_ID] } + | --- + | ... +-- Decoding of the response will fail if there's no body. +response = iproto_request(socket, header, body) + | --- + | ... +response.body + | --- + | - {} + | ... + +box.schema.user.revoke('guest', 'read, write, execute', 'universe') + | --- + | ... +socket:close() + | --- + | - true + | ... + diff --git a/test/box/gh-4769-unprepare-response-body.test.lua b/test/box/gh-4769-unprepare-response-body.test.lua new file mode 100644 index 000000000..70e41b3e5 --- /dev/null +++ b/test/box/gh-4769-unprepare-response-body.test.lua @@ -0,0 +1,30 @@ +test_run = require('test_run').new() +test_run:cmd("setopt delimiter ';'") + +net_box = require('net.box') +msgpack = require('msgpack') +urilib = require('uri') + +IPROTO_REQUEST_TYPE = 0x00 +IPROTO_PREPARE = 13 +IPROTO_SQL_TEXT = 0x40 +IPROTO_STMT_ID = 0x43 + +test_run:cmd("setopt delimiter ''"); + +box.schema.user.grant('guest', 'read, write, execute', 'universe') +uri = urilib.parse(box.cfg.listen) +socket = net_box.establish_connection(uri.host, uri.service) + +header = { [IPROTO_REQUEST_TYPE] = IPROTO_PREPARE } +body = { [IPROTO_SQL_TEXT] = 'SELECT 1' } +response = iproto_request(socket, header, body) + +body = { [IPROTO_STMT_ID] = response['body'][IPROTO_STMT_ID] } +-- Decoding of the response will fail if there's no body. +response = iproto_request(socket, header, body) +response.body + +box.schema.user.revoke('guest', 'read, write, execute', 'universe') +socket:close() + -- 2.21.1 (Apple Git-122.3)