From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id F099629F40 for ; Tue, 28 Aug 2018 12:22:45 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id srt22NcpOTBI for ; Tue, 28 Aug 2018 12:22:45 -0400 (EDT) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 89F2E29F39 for ; Tue, 28 Aug 2018 12:22:45 -0400 (EDT) Received: by mail-lf1-f48.google.com with SMTP id g9-v6so1892424lfh.1 for ; Tue, 28 Aug 2018 09:22:45 -0700 (PDT) From: Olga Arkhangelskaia Subject: [tarantool-patches] [PATCH] box: fix assertion with duplication in repl. source Date: Tue, 28 Aug 2018 19:22:26 +0300 Message-Id: <20180828162226.53550-1-krishtal.olja@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Olga Arkhangelskaia When we try to connect one master more than once we used to have assertion instead of error. Closes #3610 --- https://github.com/tarantool/tarantool/issues/3610 https://github.com/tarantool/tarantool/tree/OKriw/assert_fail_when_connect_master_twice src/box/box.cc | 14 ++++++++++++++ test/box-tap/cfg.test.lua | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/box/box.cc b/src/box/box.cc index 8d7454d1f..3a571ae3c 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -369,9 +369,23 @@ static void box_check_replication(void) { int count = cfg_getarr_size("replication"); + char *repl[count-1]; for (int i = 0; i < count; i++) { const char *source = cfg_getarr_elem("replication", i); box_check_uri(source, "replication"); + repl[i] = strdup(source); + if (repl[i] == NULL) { + tnt_raise(OutOfMemory, sizeof(*source), "source", "malloc"); + } + for (int j = i; j >= 1; j--) { + if (strcmp(repl[i], repl[j-1]) == 0) { + tnt_raise(ClientError, ER_CFG, "replication", + "duplication of replication source"); + } + } + } + for (int i = 0; i < count; i++) { + free(repl[i]); } } diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua index 5e72004ca..b227c5edb 100755 --- a/test/box-tap/cfg.test.lua +++ b/test/box-tap/cfg.test.lua @@ -6,7 +6,7 @@ local socket = require('socket') local fio = require('fio') local uuid = require('uuid') local msgpack = require('msgpack') -test:plan(90) +test:plan(91) -------------------------------------------------------------------------------- -- Invalid values @@ -446,5 +446,11 @@ code = string.format(code_fmt, dir, instance_uuid, uuid.new()) test:is(run_script(code), PANIC, "replicaset_uuid mismatch") fio.rmdir(dir) +-- +--gh-3610: assertion failure when trying to connect to the same master more than once +-- +status, reason = pcall(box.cfg, {listen = 3303, replication={3303,3303}}) +test:ok(not status and reason:match("Incorrect"), "Duplication of replication source") + test:check() os.exit(0) -- 2.14.3 (Apple Git-98)