fix logs written via stdio delayed#2316
Open
PikuZheng wants to merge 1 commit into
Open
Conversation
Owner
|
应该要分析crash的原因,fprintf是带缓冲区的,更好的保证日志输出的分行,而不会错乱。 |
Contributor
Author
现在首要解决的就是卡在缓冲区不输出的问题,使用fprintf就得加上fflush()强制刷新了? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
52a35a5 将stdout输出从 write(STDOUT_FILENO)改为fprintf(stdout)。在容器环境(stdout 为 pipe、stdio 全缓冲)下可能导致日志输出卡在用户态缓冲。此时如果plugin调用tlog,在程序退出时可能会导致资源释放先于tlog缓冲输出而产生崩溃。
smartdns/src/dns_plugin.c
Lines 304 to 307 in 0c3fdd0
------------^此处建议删除dlclose(),可以有效避免退出时崩溃
本次提交弃用fprint,引入 iovec 将数据一次性提交给 write(STDOUT_FILENO),避免了stdio缓冲和字符串拼接,同时不影响现有功能。
相关日志如下: