0
我们的项目使用这个apns provider运行在centos 6.4上推送oofline味精。红宝石操作与红宝石阻止ppoll
apns提供程序刚刚从redpop队列中读取brpop,然后重新格式化数据并发送到apms msg到Apple推送服务。
最近,我遇到了APN提供商不读从Redis的队列中味精的问题,我只是与strace过程:
异常strace的结果:
tcp 0 0 ::1:39688 ::1:6379 ESTABLISHED 29452/ruby
[[email protected]]# strace -p 29452
Process 29452 attached - interrupt to quit
ppoll([{fd=56, events=POLLIN}], 1, NULL, NULL, 8
正常strace的结果:
clock_gettime(CLOCK_MONOTONIC, {9266059, 349937955}) = 0
select(9, [8], NULL, NULL, {6, 0}) = 1 (in [8], left {3, 976969})
fcntl64(8, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK)
read(8, "*-1\r\n", 1024) = 5
write(8, "*3\r\n$5\r\nbrpop\r\n$9\r\napn_queue\r\n$1"..., 37) = 37
fcntl64(8, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK)
read(8, 0x9a0e5d8, 1024) = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {9266061, 374086306}) = 0
select(9, [8], NULL, NULL, {6, 0}^C <unfinished ...>
Process 20493 detached
这里是相关的代码:
loop do
begin
message = @redis.brpop(self.queue, 1)
if message
APN.log(:info, "---------->#{message} ----------->\n")
@notification = APN::Notification.new(JSON.parse(message.last,:symbolize_names => true))
send_notification
end
rescue Exception => e
if e.class == Interrupt || e.class == SystemExit
APN.log(:info, 'Shutting down...')
exit(0)
end
APN.log(:error, "class: #{e.class} Encountered error: #{e}, backtrace #{e.backtrace}")
APN.log(:info, 'Trying to reconnect...')
client.connect!
APN.log(:info, 'Reconnected')
client.push(@notification)
end
end
此问题发生不定期,期间时间可能是一个或两个月。
我觉得代码逻辑是对的,猜测系统网络可能会影响编程的正常运行。
当我使用pkill [pid]杀死程序时,它只是恢复正常的开始从队列中读msg开始。
现在我不知道如何分析问题,所以我必须使用cron重新启动或每隔一段时间发送一次kill信号给程序。 :(
每个人都可以有想法来处理这个问题?