Commit 28f27a9296ab3c0210aa471c26f675a5d81c33dd

Authored by Felix Bünemann
1 parent 2932cb6f
Exists in master and in 1 other branch production

Fix GtalkService Keeaplive-Thread leak

The GoogleTalk/Jabber Notification Service was leaking keepalive
threads, because xmpp4r creates an internal keealive thread on
connect that is only cleaned up when closing the client.

This lead to workers quickly running out of threads and throwing
exceptions like `ThreadError: can't alloc thread`.
app/models/notification_services/gtalk_service.rb
@@ -53,6 +53,8 @@ class NotificationServices::GtalkService < NotificationService @@ -53,6 +53,8 @@ class NotificationServices::GtalkService < NotificationService
53 # post the issue to the xmpp room(s) 53 # post the issue to the xmpp room(s)
54 send_to_users(client, message) unless user_id.blank? 54 send_to_users(client, message) unless user_id.blank?
55 send_to_muc(client, message) unless room_id.blank? 55 send_to_muc(client, message) unless room_id.blank?
  56 + ensure
  57 + client.close unless client.nil?
56 end 58 end
57 59
58 private 60 private
spec/models/notification_service/gtalk_service_spec.rb
@@ -28,6 +28,7 @@ describe NotificationService::GtalkService do @@ -28,6 +28,7 @@ describe NotificationService::GtalkService do
28 28
29 #assert 29 #assert
30 expect(gtalk).to receive(:send).exactly(2).times.with(message) 30 expect(gtalk).to receive(:send).exactly(2).times.with(message)
  31 + expect(gtalk).to receive(:close)
31 32
32 notification_service.create_notification(problem) 33 notification_service.create_notification(problem)
33 end 34 end
@@ -57,6 +58,7 @@ describe NotificationService::GtalkService do @@ -57,6 +58,7 @@ describe NotificationService::GtalkService do
57 expect(Jabber::Message).to receive(:new).with("fourth@domain.org", @error_msg) 58 expect(Jabber::Message).to receive(:new).with("fourth@domain.org", @error_msg)
58 expect(Jabber::MUC::SimpleMUCClient).to_not receive(:new) 59 expect(Jabber::MUC::SimpleMUCClient).to_not receive(:new)
59 expect(@gtalk).to receive(:send).exactly(4).times 60 expect(@gtalk).to receive(:send).exactly(4).times
  61 + expect(@gtalk).to receive(:close)
60 62
61 @notification_service.user_id = "first@domain.org,second@domain.org, third@domain.org , fourth@domain.org " 63 @notification_service.user_id = "first@domain.org,second@domain.org, third@domain.org , fourth@domain.org "
62 @notification_service.room_id = "" 64 @notification_service.room_id = ""
@@ -69,6 +71,7 @@ describe NotificationService::GtalkService do @@ -69,6 +71,7 @@ describe NotificationService::GtalkService do
69 expect(Jabber::Message).to receive(:new).with("fourth@domain.org", @error_msg) 71 expect(Jabber::Message).to receive(:new).with("fourth@domain.org", @error_msg)
70 expect(Jabber::MUC::SimpleMUCClient).to_not receive(:new) 72 expect(Jabber::MUC::SimpleMUCClient).to_not receive(:new)
71 expect(@gtalk).to receive(:send).exactly(4).times 73 expect(@gtalk).to receive(:send).exactly(4).times
  74 + expect(@gtalk).to receive(:close)
72 75
73 @notification_service.user_id = "first@domain.org;second@domain.org; third@domain.org ; fourth@domain.org " 76 @notification_service.user_id = "first@domain.org;second@domain.org; third@domain.org ; fourth@domain.org "
74 @notification_service.room_id = "" 77 @notification_service.room_id = ""
@@ -81,6 +84,7 @@ describe NotificationService::GtalkService do @@ -81,6 +84,7 @@ describe NotificationService::GtalkService do
81 expect(Jabber::Message).to receive(:new).with("fourth@domain.org", @error_msg) 84 expect(Jabber::Message).to receive(:new).with("fourth@domain.org", @error_msg)
82 expect(Jabber::MUC::SimpleMUCClient).to_not receive(:new) 85 expect(Jabber::MUC::SimpleMUCClient).to_not receive(:new)
83 expect(@gtalk).to receive(:send).exactly(4).times 86 expect(@gtalk).to receive(:send).exactly(4).times
  87 + expect(@gtalk).to receive(:close)
84 88
85 @notification_service.user_id = "first@domain.org second@domain.org third@domain.org fourth@domain.org " 89 @notification_service.user_id = "first@domain.org second@domain.org third@domain.org fourth@domain.org "
86 @notification_service.room_id = "" 90 @notification_service.room_id = ""
@@ -117,6 +121,7 @@ describe NotificationService::GtalkService do @@ -117,6 +121,7 @@ describe NotificationService::GtalkService do
117 121
118 #assert 122 #assert
119 expect(gtalk).to receive(:send).with(message) 123 expect(gtalk).to receive(:send).with(message)
  124 + expect(gtalk).to receive(:close)
120 125
121 notification_service.create_notification(problem) 126 notification_service.create_notification(problem)
122 end 127 end