From 24183d3f86abff528100fb4fdb8330e289ce0dba Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Thu, 18 Jul 2024 09:58:23 +0800 Subject: [PATCH 1/3] fix: start udfd with env var --- source/libs/function/src/tudf.c | 2 ++ source/libs/function/src/udfd.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 5f7764f342..a38dc4e42a 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -71,6 +71,7 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) { } } +extern char **environ; static int32_t udfSpawnUdfd(SUdfdData *pData) { fnInfo("start to init udfd"); uv_process_options_t options = {0}; @@ -117,6 +118,7 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) { child_stdio[2].data.fd = 2; options.stdio_count = 3; options.stdio = child_stdio; + options.env = environ; options.flags = UV_PROCESS_DETACHED; diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index df97e873aa..75bed73bb3 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -1421,22 +1421,26 @@ int main(int argc, char *argv[]) { if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); + taosCloseLog(); return -2; } initEpSetFromCfg(tsFirst, tsSecond, &global.mgmtEp); if (udfdOpenClientRpc() != 0) { fnError("open rpc connection to mnode failed"); + taosCloseLog(); return -3; } if (udfdCreateUdfSourceDir() != 0) { fnError("create udf source directory failed"); + taosCloseLog(); return -4; } if (udfdUvInit() != 0) { fnError("uv init failure"); + taosCloseLog(); return -5; } @@ -1452,6 +1456,7 @@ int main(int argc, char *argv[]) { udfdDeinitScriptPlugins(); + taosCloseLog(); udfdCleanup(); return 0; } From e8218f7f6389ad6fc6e9ebb607ccffb288090270 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Thu, 18 Jul 2024 12:18:17 +0800 Subject: [PATCH 2/3] fix: set fqdn for udfd --- source/libs/function/src/tudf.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index a38dc4e42a..6b6eb0f439 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -71,7 +71,6 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) { } } -extern char **environ; static int32_t udfSpawnUdfd(SUdfdData *pData) { fnInfo("start to init udfd"); uv_process_options_t options = {0}; @@ -118,7 +117,6 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) { child_stdio[2].data.fd = 2; options.stdio_count = 3; options.stdio = child_stdio; - options.env = environ; options.flags = UV_PROCESS_DETACHED; @@ -145,14 +143,29 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) { udfdPathLdLib[udfdLdLibPathLen] = ':'; strncpy(udfdPathLdLib + udfdLdLibPathLen + 1, pathTaosdLdLib, sizeof(udfdPathLdLib) - udfdLdLibPathLen - 1); if (udfdLdLibPathLen + taosdLdLibPathLen < 1024) { - fnInfo("udfd LD_LIBRARY_PATH: %s", udfdPathLdLib); + fnInfo("[UDFD]udfd LD_LIBRARY_PATH: %s", udfdPathLdLib); } else { - fnError("can not set correct udfd LD_LIBRARY_PATH"); + fnError("[UDFD]can not set correct udfd LD_LIBRARY_PATH"); } char ldLibPathEnvItem[1024 + 32] = {0}; snprintf(ldLibPathEnvItem, 1024 + 32, "%s=%s", "LD_LIBRARY_PATH", udfdPathLdLib); - char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, ldLibPathEnvItem, NULL}; + char *taosFqdnEnvItem = NULL; + char *taosFqdn = getenv("TAOS_FQDN"); + if (taosFqdn != NULL) { + taosFqdnEnvItem = taosMemoryMalloc(strlen("TAOS_FQDN=") + strlen(taosFqdn) + 1); + if (taosFqdnEnvItem != NULL) { + strcpy(taosFqdnEnvItem, "TAOS_FQDN="); + strcat(taosFqdnEnvItem, taosFqdn); + fnInfo("[UDFD]Succsess to set TAOS_FQDN:%s", taosFqdn); + } else { + fnError("[UDFD]Failed to allocate memory for TAOS_FQDN"); + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, ldLibPathEnvItem,taosFqdnEnvItem, NULL}; + options.env = envUdfd; int err = uv_spawn(&pData->loop, &pData->process, &options); From 960103a6ef1b7c377fc3791ba71be5fcfeffecf3 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Thu, 18 Jul 2024 13:58:47 +0800 Subject: [PATCH 3/3] fix: mem leak --- source/libs/function/src/tudf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 6b6eb0f439..3c5e4014b3 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -195,6 +195,7 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) { } else { fnInfo("udfd is initialized"); } + if(taosFqdnEnvItem) taosMemoryFree(taosFqdnEnvItem); return err; }