Commit c5f5efb12c3c11cdd08761a7c86069701efba0e9

Authored by Arthur Nogueira Neves
2 parents 2932cb6f 28f27a92
Exists in master and in 1 other branch production

Merge pull request #797 from felixbuenemann/fix-gtalk-keepalive-thread-leak

Fix GtalkService Keeaplive-Thread leak
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