gpt4 book ai didi

mysql - 调试陈旧的 Ruby 进程

转载 作者:行者123 更新时间:2023-11-30 23:42:09 26 4
gpt4 key购买 nike

我在 Rails 项目中有一个 ruby​​ 脚本。该脚本包含 environment.rb 以便加载 Rails 等。然后它会监听另一台服务器的 TCP 套接字上的数据,解析它以保持 mysql 数据库最新。

我正在使用守护进程 gem 来轻松启动和停止进程。我让脚本在生产中运行了一天多没有问题,但现在它已经过时了。 Daemons 控制文件显示该进程仍在运行,当我执行 ps -ef 时该进程显示出来并且 monit 也认为该进程运行良好。但是数据库没有更新(如果我在另一个进程中再次运行脚本,数据库会正确更新)。

我尝试使用 GDB 通过运行 sudo gdb/usr/local/bin/ruby 25395 来调试进程的问题,其输出是

GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
/usr/local/bin/ruby: No such file or directory.
Attaching to process 25395
Reading symbols from /usr/bin/ruby1.8...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libruby1.8.so.1.8...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libruby1.8.so.1.8
Reading symbols from /lib/libpthread.so.0...
(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x2b7decb08d30 (LWP 25395)]
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libcrypt.so.1...
(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libc.so.6...
(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/thread.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/thread.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/etc.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/etc.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/stringio.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/stringio.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/syck.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/syck.so
Reading symbols from /lib/libnss_compat.so.2...
(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_compat.so.2
Reading symbols from /lib/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libnss_nis.so.2...
(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_nis.so.2
Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_files.so.2
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/socket.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/socket.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/nkf.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/nkf.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/bigdecimal.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/bigdecimal.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/iconv.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/iconv.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/strscan.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/strscan.so
Reading symbols from /usr/lib/ruby/gems/1.8/gems/hpricot-0.8.1/lib/fast_xs.so...done.
Loaded symbols for /usr/lib/ruby/gems/1.8/gems/hpricot-0.8.1/lib/fast_xs.so
Reading symbols from /usr/lib/ruby/gems/1.8/gems/json-1.1.9/ext/json/ext/parser.so...done.
Loaded symbols for /usr/lib/ruby/gems/1.8/gems/json-1.1.9/ext/json/ext/parser.so
Reading symbols from /usr/lib/ruby/gems/1.8/gems/json-1.1.9/ext/json/ext/generator.so...done.
Loaded symbols for /usr/lib/ruby/gems/1.8/gems/json-1.1.9/ext/json/ext/generator.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/racc/cparse.so...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/racc/cparse.so
Reading symbols from /usr/lib/ruby/gems/1.8/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/tmailscanner.so...done.
Loaded symbols for /usr/lib/ruby/gems/1.8/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/tmailscanner.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/openssl.so...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/openssl.so
Reading symbols from /lib/libssl.so.0.9.8...done.
Loaded symbols for /lib/libssl.so.0.9.8
Reading symbols from /lib/libcrypto.so.0.9.8...done.
Loaded symbols for /lib/libcrypto.so.0.9.8
Reading symbols from /lib/libz.so.1...done.
Loaded symbols for /lib/libz.so.1
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/digest.so...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/digest.so
Reading symbols from /usr/lib/ruby/1.8/x86_64-linux/fcntl.so...done.
Loaded symbols for /usr/lib/ruby/1.8/x86_64-linux/fcntl.so
Reading symbols from /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so...done.
Loaded symbols for /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
Reading symbols from /usr/lib/libmysqlclient.so.15...done.
Loaded symbols for /usr/lib/libmysqlclient.so.15
0x00002b7dec86df10 in read ()
from /lib/libc.so.6

这表明问题出在 mysql 连接上。有可能几个小时没有任何数据。我相信这会导致进程与 Mysql 断开连接?但如果确实发生了这种情况,我会认为当脚本再次开始获取数据时,会抛出一个异常,该异常会停止脚本运行,提示 monit 重新启动它。

最佳答案

我解决了这个问题,实际上是 TCP 连接断开。即使在重新连接之后,套接字上的 gets 方法也会挂起。我使用的解决方案是在 gets 方法周围放置一个超时 block ​​。例如

timeout(10) do    
line = socket.gets
end

这将在超时结束脚本后引发异常。然后 Monit 可以自动重启它。

关于mysql - 调试陈旧的 Ruby 进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2172182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com