Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用中碰到的两个崩溃问题 #142

Open
v172744v opened this issue Aug 27, 2024 · 0 comments
Open

使用中碰到的两个崩溃问题 #142

v172744v opened this issue Aug 27, 2024 · 0 comments

Comments

@v172744v
Copy link

1、单机多实例崩溃的问题
2、大配置文件导致的崩溃问题

问题1:
查看源码看到会默认监听30620 udp端口,当该端口已被占用时就会造成崩溃。。。(这是我碰到的崩溃问题,其他朋友可能不一样)
该问题解决也好解决,只是我没有在文档里看到相关的处理信息,最终是靠看源码了解到的:
上一段我的代码片段,就好理解了:
m_Properties[PropertyKeyConst::SERVER_ADDR] = m_conf.nacos_ip_port.data();
m_Properties[PropertyKeyConst::NAMESPACE] = m_conf.name_space.data();
if(!m_conf.udp_receiver_port.empty())
m_Properties[PropertyKeyConst::UDP_RECEIVER_PORT] = m_conf.udp_receiver_port.data(); //未配置时nacos内置默认udp接收端口30620
m_p_INacosServiceFactory = NacosFactoryFactory::getNacosFactory(m_Properties);
m_p_ResourceGuard_INacosServiceFactory = new ResourceGuard(m_p_INacosServiceFactory);

问题2:
有时候配置文件更新时会崩溃,查看源码中看到的:
NacosString IOUtils::readStringFromFile(const NacosString &file, const NacosString &encoding) NACOS_THROW(IOException) {
size_t toRead = getFileSize(file);
FILE *fp = fopen(file.c_str(), "rb");
if (fp == NULL) {
throw IOException(NacosException::FILE_NOT_FOUND, "File not found:" + file);
}
char buf[toRead + 1];
fread(buf, toRead, 1, fp);
buf[toRead] = '\0';
fclose(fp);
return NacosString(buf);
}

上面代码就比较直观了,文件内容根据大小读取到了栈内存,这就意味着文件不能太大,太大就栈溢出了。。。我是在linux下使用,文件刚好超过8MB,所以我的临时解决办法是用命令扩大了栈内存,考虑以后的更新,我没有去动源码。还好我们配置文件比较大的概率还是很低的,只是部分现场请实施留意了这一点,期望SDK更新中...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant