【发布时间】:2016-08-03 19:04:15
【问题描述】:
我们在应用程序中使用 Apache Zookeeper Client C 绑定。客户端库版本为 3.5.1。当 Zookeeper 连接断开时,应用程序配置为退出,错误代码为 116。
Systemd 被用于自动启动/停止应用程序。单元文件不会覆盖KillMode 的默认设置,即send SIGTERM to the application。
当使用 systemctl stop 指令停止进程时,Zookeeper 客户端线程似乎正在尝试重新连接到 Zookeeper:
2016-04-12 22:34:45,799:4506(0xf14f7b40):ZOO_ERROR@handle_socket_error_msg@2363: Socket [128.0.0.4:61758] zk retcode=-4, errno=112(Host is down): failed while receiving a server response
2016-04-12 22:34:45,799:4506(0xf14f7b40):ZOO_INFO@check_events@2345: initiated connection to server [128.0.0.4:61758]
Apr 12 22:34:45 main thread: zookeeperWatcher: event type ZOO_SESSION_EVENT state ZOO_CONNECTING_STATE path
2016-04-12 22:34:45,801:4506(0xf14f7b40):ZOO_INFO@check_events@2397: session establishment complete on server [128.0.0.4:61758], sessionId=0x40000015b8d0077, negotiated timeout=20000
2016-04-12 22:34:46,476:4506(0xf14f7b40):ZOO_WARN@zookeeper_interest@2191: Delaying connection after exhaustively trying all servers [128.0.0.4:61758]
2016-04-12 22:34:46,810:4506(0xf14f7b40):ZOO_INFO@check_events@2345: initiated connection to server [128.0.0.4:61758]
2016-04-12 22:34:46,811:4506(0xf14f7b40):ZOO_ERROR@handle_socket_error_msg@2382: Socket [128.0.0.4:61758] zk retcode=-112, errno=116(Stale file handle): sessionId=0x40000015b8d0077 h
因此,进程退出并出现错误代码。 Systemd 在退出时看到失败代码并且不会尝试重新启动应用程序。有谁知道为什么客户端断开连接?
我知道我可以通过在单元文件中设置SuccessExitStatus=116 来解决这个问题,但我不想掩盖真正的错误。我尝试为 SIGTERM 注册信号处理程序并在处理程序中关闭 Zookeeper 客户端。但是当我发出 systemctl stop 时,处理程序代码似乎永远不会受到影响。
编辑:处理程序没有被调用,因为我已经使它异步 - 它没有在收到信号后立即执行。 OTOH 进程在 Zookeeper 断开连接后立即退出。
【问题讨论】:
-
这就是“不再复制”的原因,聊天中的 OP 表示“我弄清楚了我的情况发生了什么,这与我给出的描述无关。基本上我组织中的某个人正在运行一个正在杀死连接的脚本,我不知道”,因此也是 OP 的最后一票
标签: c systemd apache-zookeeper sigterm