From 1f37f59b27d15edab2f3c05f7f292fdbb6a40a48 Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Wed, 3 Aug 2022 15:25:00 +0300 Subject: [PATCH] [bug] Fix crash if connection is null; fix tenant typo --- Common/config/default.json | 2 +- Common/sources/tenantManager.js | 6 +++--- DocService/sources/DocsCoServer.js | 4 ++-- schema/postgresql/createdb.sql | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Common/config/default.json b/Common/config/default.json index 3be64ae5..f44c4dae 100644 --- a/Common/config/default.json +++ b/Common/config/default.json @@ -102,7 +102,7 @@ "baseDomain": "", "filenameSecret": "secret.key", "filenameLicense": "license.lic", - "defaultTetant": "tetant" + "defaultTenant": "localhost" }, "services": { "CoAuthoring": { diff --git a/Common/sources/tenantManager.js b/Common/sources/tenantManager.js index aec9166b..0afaa2be 100644 --- a/Common/sources/tenantManager.js +++ b/Common/sources/tenantManager.js @@ -46,7 +46,7 @@ const cfgTenantsBaseDomain = config.get('tenants.baseDomain'); const cfgTenantsBaseDir = config.get('tenants.baseDir'); const cfgTenantsFilenameSecret = config.get('tenants.filenameSecret'); const cfgTenantsFilenameLicense = config.get('tenants.filenameLicense'); -const cfgTenantsDefaultTetant = config.get('tenants.defaultTetant'); +const cfgTenantsDefaultTenant = config.get('tenants.defaultTenant'); const cfgSecretInbox = config.get('services.CoAuthoring.secret.inbox'); const cfgSecretOutbox = config.get('services.CoAuthoring.secret.outbox'); const cfgSecretSession = config.get('services.CoAuthoring.secret.session'); @@ -55,7 +55,7 @@ let licenseInfo; let licenseOriginal; function getDefautTenant() { - return cfgTenantsDefaultTetant; + return cfgTenantsDefaultTenant; } function getTenant(ctx, domain) { let tenant = getDefautTenant(); @@ -66,7 +66,7 @@ function getTenant(ctx, domain) { if (-1 !== index) { tenant = domain.substring(0, index); } else { - ctx.logger.warn('getTenant invalid domain=%s', domain); + tenant = domain; } } return tenant; diff --git a/DocService/sources/DocsCoServer.js b/DocService/sources/DocsCoServer.js index 6ce04971..e4de152b 100644 --- a/DocService/sources/DocsCoServer.js +++ b/DocService/sources/DocsCoServer.js @@ -1300,12 +1300,12 @@ exports.install = function(server, callbackFunction) { var sockjs_echo = sockjs.createServer(cfgSockjs); sockjs_echo.on('connection', function(conn) { - let ctx = new operationContext.Context(); - ctx.initFromConnection(conn); if (!conn) { operationContext.global.logger.error("null == conn"); return; } + let ctx = new operationContext.Context(); + ctx.initFromConnection(conn); if (getIsShutdown()) { sendFileError(ctx, conn, 'Server shutdow'); return; diff --git a/schema/postgresql/createdb.sql b/schema/postgresql/createdb.sql index b1a0b0d9..e1fc6e83 100644 --- a/schema/postgresql/createdb.sql +++ b/schema/postgresql/createdb.sql @@ -40,7 +40,7 @@ PRIMARY KEY ("tenant", "id") ) WITH (OIDS=FALSE); -CREATE OR REPLACE FUNCTION merge_db(_tetant varchar(255), _id varchar(255), _status int2, _status_info int4, _last_open_date timestamp without time zone, _user_index int4, _change_id int4, _callback text, _baseurl text, OUT isupdate char(5), OUT userindex int4) AS +CREATE OR REPLACE FUNCTION merge_db(_tenant varchar(255), _id varchar(255), _status int2, _status_info int4, _last_open_date timestamp without time zone, _user_index int4, _change_id int4, _callback text, _baseurl text, OUT isupdate char(5), OUT userindex int4) AS $$ DECLARE t_var "public"."task_result"."user_index"%TYPE; @@ -49,9 +49,9 @@ BEGIN -- first try to update the key -- note that "a" must be unique IF ((_callback <> '') IS TRUE) AND ((_baseurl <> '') IS TRUE) THEN - UPDATE "public"."task_result" SET last_open_date=_last_open_date, user_index=user_index+1,callback=_callback,baseurl=_baseurl WHERE tenant = _tetant AND id = _id RETURNING user_index into userindex; + UPDATE "public"."task_result" SET last_open_date=_last_open_date, user_index=user_index+1,callback=_callback,baseurl=_baseurl WHERE tenant = _tenant AND id = _id RETURNING user_index into userindex; ELSE - UPDATE "public"."task_result" SET last_open_date=_last_open_date, user_index=user_index+1 WHERE tenant = _tetant AND id = _id RETURNING user_index into userindex; + UPDATE "public"."task_result" SET last_open_date=_last_open_date, user_index=user_index+1 WHERE tenant = _tenant AND id = _id RETURNING user_index into userindex; END IF; IF found THEN isupdate := 'true'; @@ -61,7 +61,7 @@ BEGIN -- if someone else inserts the same key concurrently, -- we could get a unique-key failure BEGIN - INSERT INTO "public"."task_result"(id, status, status_info, last_open_date, user_index, change_id, callback, baseurl) VALUES(_tetant, _id, _status, _status_info, _last_open_date, _user_index, _change_id, _callback, _baseurl) RETURNING user_index into userindex; + INSERT INTO "public"."task_result"(id, status, status_info, last_open_date, user_index, change_id, callback, baseurl) VALUES(_tenant, _id, _status, _status_info, _last_open_date, _user_index, _change_id, _callback, _baseurl) RETURNING user_index into userindex; isupdate := 'false'; RETURN; EXCEPTION WHEN unique_violation THEN