当前位置: 首页 > news >正文

getaddrinfo调用crash 的debug过程

         前两天,产线报一例crash问题。拿到core文件后,栈展开信息:

(gdb) bt
#0  0x00007f64a3651aff in raise () from /lib64/libc.so.6
#1  0x00007f64a3624ea5 in abort () from /lib64/libc.so.6
#2  0x00007f64a3694097 in __libc_message () from /lib64/libc.so.6
#3  0x00007f64a369415a in __libc_fatal () from /lib64/libc.so.6
#4  0x00007f64a374fc44 in __netlink_assert_response () from /lib64/libc.so.6
#5  0x00007f64a374c762 in __netlink_request () from /lib64/libc.so.6
#6  0x00007f64a374c901 in getifaddrs_internal () from /lib64/libc.so.6
#7  0x00007f64a374d608 in getifaddrs () from /lib64/libc.so.6
#8  0x00007f64a47ecdd0 in bsd_localinfo (return_result=0x7f649d12a6b8, hints=0x7f649d12a6f0) at su_localinfo.c:1167
#9  su_getlocalinfo (hints=hints@entry=0x7f649d12a7d0, return_localinfo=return_localinfo@entry=0x7f649d12a7c8) at su_localinfo.c:242
#10 0x00007f64a47ca9ea in soa_init_sdp_connection_with_session (ss=ss@entry=0x7f64880603a0, c=0x7f649d12a940, buffer=buffer@entry=0x7f649d12a9a0 "10.10.50.52", sdp=sdp@entry=0x7f649d12a9e0) at soa.c:2326
......

看来像是getifaddrs 调用出了什么问题。拿不到产线的系统日志。幸运的是栈里保留了一点信息,跳转到第四帧,查看下汇编:

(gdb) f 4
#4  0x00007f64a374fc44 in __netlink_assert_response () from /lib64/libc.so.6
(gdb) disassemble 

 从这里看,触发crash前应该有打印出什么信息,把寄存器指向的内存解出来看看:

(gdb) x/s $r12
0x7f649d129380:	"Unexpected error 9 on netlink descriptor 19.\n"

找到了gilbc的打印内容:  "Unexpected error 9 on netlink descriptor 19.\n",知道error number为9 (EBADF) ,操作的FD值为19。

外事不明问谷歌,找到这个:

https://stackoverflow.com/questions/58827641/getaddrinfo-calls-assert-in-the-program/59615786#59615786https://stackoverflow.com/questions/58827641/getaddrinfo-calls-assert-in-the-program/59615786#59615786似乎是对应上了这段说明:

This is a file descriptor race in the application. The typical scenario for error 9 (EBADF) looks like this:

  1. Thread A closes a file descriptor.
  2. Thread B calls getaddrinfo and opens a Netlink socket. It happens to receive the same descriptor value.
  3. Due to a bug, thread A closes the same file descriptor again. Normally, that would be benign, but due to the concurrent execution, the Netlink socket created by glibc is closed.
  4. Thread B attempts to use the Netlink socket descriptor and receives the EBADF error.

The key to fixing such bugs is figuring out where exactly the double-close happens.

尝试重现,然后用strace跟踪系统调用:

 strace -o output.txt -T -tt -e trace=all -fp 1039

上面命令中的output.txt是输出的文件名,1039是进程的PID。

重现后打开output.txt,果然找到这样的错误:

这下实锤了,有个FD19重复close。

接下来的事,就是检查代码,解决重复close的地方了。 

http://www.lryc.cn/news/62267.html

相关文章:

  • 【Sql】sql语句练习随记
  • IDEA社区版搭建Tomcat服务器并创建web项目
  • C++ [STL-简介]
  • 牛客前端编程语言错题2
  • 【C语言】基础语法3:控制流程结构
  • MySQL安全性:防止攻击和保护数据
  • R语言结构方程模型(SEM)
  • 软件or硬件?硬件的前途到底在哪里?
  • 同学在外包干了两年的点点点,24岁人就快废了
  • 基于Java springboot 疫情在线网课管理系统
  • Unity Camera -- (3)控制相机能看到的东西
  • 《基于深度迁移学习的可穿戴睡眠阶段分类》阅读笔记
  • java版工程管理系统源码企业工程项目管理系统简介
  • 机器学习算法 决策树
  • 论文笔记:An Interactive-Voting Based Map Matching Algorithm
  • _awt_container容器_演示
  • TryHackMe-Misguided Ghosts(boot2root)
  • 【Leetcode】10. 正则表达式匹配
  • 不得不说的结构型模式-装饰器模式
  • Flutter+YesAPI 快速构建零运维的APP
  • 使用Socks5代理保障HTTP传输的网络安全
  • C语言入门篇——操作符篇
  • YOLOv7训练自己的数据集(txt文件,笔记)
  • 防止机械/移动硬盘休眠 - NoSleepHD
  • (二)app自动化脚本录制回放
  • STM32HAL库USART外设配置流程及库函数讲解
  • Qt 实现TCP通信和UDP通信
  • 完成近4亿元C轮融资+自研底盘域控,本土线控制动玩家“拼”了
  • 【UE】一个简易的游戏计时器
  • Leetcode力扣秋招刷题路-0455