message_bus 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of message_bus might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65597f9dd4a3b22117b594ccaff431aa8ed63198
4
- data.tar.gz: 66c1a2a4079eb8d685e6029f1c0a6da4ecb7b7d3
3
+ metadata.gz: 6909db1677e03068c2536f5576a123e371f946dd
4
+ data.tar.gz: a4aab49db0edf4340ca5cd84a9f6c4a75f2928bf
5
5
  SHA512:
6
- metadata.gz: 6b5e51a5a51aec25039cef045b5c75cd4b27e610c7f96c7fa694aee4c7cc0a65b43be5224b8daed76f3a20908a8382baee9c20b15f281c5d76573c135599ea5e
7
- data.tar.gz: 121e47af10c76c4ad0ffc7cd70f679632c9be4808adae2314ef977bafd82a341456feb5d18b2ac14827ee2abb4bf7723aad759df87ddab0330c054fd1787bfc2
6
+ metadata.gz: be441795c69094b47ac1860310ff33e35bb1a61920ed31f93bffd5425a13a505f6ff8d0a04b19779700ed457c263414be5daa6001c349925880958acd966bdd3
7
+ data.tar.gz: 455e07565586f43d12d89fbe7ee79177aad36973b5f4576d5cdafbebd9f9249b370df3f8023a77575c32e4cc697c4b4a44b501b161a6fcfec14d5021d808c811
data/.travis.yml CHANGED
@@ -3,7 +3,8 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.2
6
+ - 2.2
6
7
  gemfile:
7
8
  - Gemfile
8
9
  services:
9
- - redis-server
10
+ - redis-server
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 08-06-2015
2
+ - Version 1.0.14
3
+ - Fix: we can not use Thread#kill best keepalive can do is terminate process cleanly
4
+ - Feature: you can opt-out of keepalive with MessageBus.keepalive_timeout = 0
5
+
1
6
  08-06-2015
2
7
  - Version 1.0.13
3
8
  - Fix: on global subscribe reconnect replay missed messages
data/README.md CHANGED
@@ -67,7 +67,7 @@ end
67
67
 
68
68
  MessageBus can be used in an environment that hosts multiple sites by multiplexing channels. To use this mode
69
69
 
70
- ```
70
+ ```ruby
71
71
  # define a site_id lookup method
72
72
  MessageBus.site_id_lookup do
73
73
  some_method_that_returns_site_id_string
data/lib/message_bus.rb CHANGED
@@ -328,6 +328,17 @@ module MessageBus::Implementation
328
328
  end
329
329
  end
330
330
 
331
+ # set to 0 to disable, anything higher and
332
+ # a keepalive will run every N seconds, if it fails
333
+ # process is killed
334
+ def keepalive_interval=(interval)
335
+ @keepalive_interval = interval
336
+ end
337
+
338
+ def keepalive_interval
339
+ @keepalive_interval || 60
340
+ end
341
+
331
342
  protected
332
343
 
333
344
  def global?(channel)
@@ -385,9 +396,10 @@ module MessageBus::Implementation
385
396
  end
386
397
  end
387
398
 
388
- KEEPALIVE_INTERVAL = 60
399
+ MIN_KEEPALIVE = 20
389
400
 
390
401
  def new_subscriber_thread
402
+
391
403
  thread = Thread.new do
392
404
  begin
393
405
  global_subscribe_thread unless @destroyed
@@ -395,25 +407,36 @@ module MessageBus::Implementation
395
407
  MessageBus.logger.warn "Unexpected error in subscriber thread #{e}"
396
408
  end
397
409
  end
410
+
398
411
  blk = proc do
399
412
  if !@destroyed && thread.alive?
400
413
  publish("/__mb_keepalive__/", Process.pid, user_ids: [-1])
401
- if Time.now - (@last_message || Time.now) > KEEPALIVE_INTERVAL*2
402
- MessageBus.logger.warn "Global messages on #{Process.pid} timed out, restarting thread"
414
+ if (Time.now - (@last_message || Time.now)) > keepalive_interval*2
415
+ MessageBus.logger.warn "Global messages on #{Process.pid} timed out, restarting process"
403
416
  # No other clean way to remove this thread, its listening on a socket
404
417
  # no data is arriving
405
418
  #
406
419
  # In production we see this kind of situation ... sometimes ... when there is
407
420
  # a VRRP failover, or weird networking condition
408
- thread.kill
409
- sleep 1
410
- ensure_subscriber_thread
421
+ pid = Process.pid
422
+
423
+ # do the best we can to terminate self cleanly
424
+ fork do
425
+ Process.kill('TERM', pid)
426
+ sleep 10
427
+ Process.kill('KILL', pid)
428
+ end
429
+
430
+ sleep 10
431
+ Process.kill('KILL', pid)
432
+
411
433
  else
412
- timer.queue(KEEPALIVE_INTERVAL, &blk)
434
+ timer.queue(keepalive_interval, &blk) if keepalive_interval > MIN_KEEPALIVE
413
435
  end
414
436
  end
415
437
  end
416
- timer.queue(KEEPALIVE_INTERVAL, &blk)
438
+
439
+ timer.queue(keepalive_interval, &blk) if keepalive_interval > MIN_KEEPALIVE
417
440
 
418
441
  thread
419
442
  end
@@ -421,7 +444,7 @@ module MessageBus::Implementation
421
444
  def global_subscribe_thread
422
445
  # pretend we just got a message
423
446
  @last_message = Time.now
424
- reliable_pub_sub.global_subscribe(@global_id) do |msg|
447
+ reliable_pub_sub.global_subscribe do |msg|
425
448
  begin
426
449
  @last_message = Time.now
427
450
  decode_message!(msg)
@@ -429,7 +452,6 @@ module MessageBus::Implementation
429
452
 
430
453
  @mutex.synchronize do
431
454
  raise MessageBus::BusDestroyed if @destroyed
432
- @last_message_time = Time.now
433
455
  globals = @subscriptions[nil]
434
456
  locals = @subscriptions[msg.site_id] if msg.site_id
435
457
 
@@ -48,7 +48,7 @@ class MessageBus::Redis::ReliablePubSub
48
48
 
49
49
  def redis_channel_name
50
50
  db = @redis_config[:db] || 0
51
- "discourse_#{db}"
51
+ "_message_bus_#{db}"
52
52
  end
53
53
 
54
54
  # redis connection used for publishing messages
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "1.0.13"
2
+ VERSION = "1.0.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack