logjam_agent 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b543de9e4f7a8d5ae896a7c2fa4524a8b220a1dad8a6b4e1be6b5eee4c8110e
4
- data.tar.gz: 62f2aee617a120107307e625b2ba2df8fb461f53ba9fa3baff0ce0187fc1325f
3
+ metadata.gz: df4bc6a68ce75215afa172d8247bffc2fd1192651e2410e26d4c298500bf4934
4
+ data.tar.gz: 54067782beccfe222468f27d1062d4c8cf65f9dd7e4fd94abaa24e2f3eaa46fc
5
5
  SHA512:
6
- metadata.gz: ec3578d040a1033e06029caf81256e6524a66a7c8c24493e986e467a603564e53b22cc05eadf243a3310ccfb8b3b065c012759e5d21d2acd9e64b597e4fb6710
7
- data.tar.gz: ed17803ea6301229c58b82e2886cf82bb36fa88554567f5864e0d38df653a2b2a07fe76160b49de55ef03619b745608e95648364532f3f7e465021a558ae7ae1
6
+ metadata.gz: 2eec84c0f349756469546bb35d0ae047585149e9c11429daad6701d98a4d104c9ab4161aa342be12790fd9eb46a4ee47c766a7e8cd3930388e584b31317ecf90
7
+ data.tar.gz: 941264e9a1eeeedf6a44748d02e8fb825c59402e28fb66244f3ff9b1045dfa097d5763503ad23b8ff53398560684a576462f1084343b9f2d539e9b37ff9c3386
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.31.0"
2
+ VERSION = "0.32.0"
3
3
  end
@@ -16,6 +16,7 @@ module LogjamAgent
16
16
  @sequence = SEQUENCE_START
17
17
  @socket = nil
18
18
  @ping_ensured = false
19
+ @socket_mutex = Mutex.new
19
20
  end
20
21
 
21
22
  def connection_specs
@@ -35,11 +36,11 @@ module LogjamAgent
35
36
  }
36
37
  end
37
38
 
38
- @@mutex = Mutex.new
39
+ @@context_mutex = Mutex.new
39
40
  @@zmq_context = nil
40
41
 
41
42
  def self.context
42
- @@mutex.synchronize do
43
+ @@context_mutex.synchronize do
43
44
  @@zmq_context ||=
44
45
  begin
45
46
  require 'ffi-rzmq'
@@ -50,29 +51,12 @@ module LogjamAgent
50
51
  end
51
52
  end
52
53
 
53
- def socket
54
- return @socket if @socket
55
- @socket = self.class.context.socket(ZMQ::DEALER)
56
- raise "ZMQ error on socket creation: #{ZMQ::Util.error_string}" if @socket.nil?
57
- if LogjamAgent.ensure_ping_at_exit
58
- ensure_ping_at_exit
59
- else
60
- at_exit { reset }
61
- end
62
- @socket.setsockopt(ZMQ::LINGER, @config[:linger])
63
- @socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
64
- @socket.setsockopt(ZMQ::RCVHWM, @config[:rcv_hwm])
65
- @socket.setsockopt(ZMQ::RCVTIMEO, @config[:rcv_timeo])
66
- @socket.setsockopt(ZMQ::SNDTIMEO, @config[:snd_timeo])
67
- spec = connection_specs.sort_by{rand}.first
68
- @socket.connect(spec)
69
- @socket
70
- end
71
-
72
54
  def reset
73
- if @socket
74
- @socket.close
75
- @socket = nil
55
+ @socket_mutex.synchronize do
56
+ if @socket
57
+ @socket.close
58
+ @socket = nil
59
+ end
76
60
  end
77
61
  end
78
62
 
@@ -89,16 +73,40 @@ module LogjamAgent
89
73
  key += ".#{engine}"
90
74
  end
91
75
  msg = LogjamAgent.encode_payload(data)
92
- if options[:sync]
93
- send_receive(app_env, key, msg)
94
- else
95
- publish(app_env, key, msg)
76
+ @socket_mutex.synchronize do
77
+ if options[:sync]
78
+ send_receive(app_env, key, msg)
79
+ else
80
+ publish(app_env, key, msg)
81
+ end
96
82
  end
97
83
  rescue => error
98
84
  reraise_expectation_errors!
99
85
  raise ForwardingError.new(error.message)
100
86
  end
101
87
 
88
+ private
89
+
90
+ # this method assumes the caller holds the socket mutex
91
+ def socket
92
+ return @socket if @socket
93
+ @socket = self.class.context.socket(ZMQ::DEALER)
94
+ raise "ZMQ error on socket creation: #{ZMQ::Util.error_string}" if @socket.nil?
95
+ if LogjamAgent.ensure_ping_at_exit
96
+ ensure_ping_at_exit
97
+ else
98
+ at_exit { reset }
99
+ end
100
+ @socket.setsockopt(ZMQ::LINGER, @config[:linger])
101
+ @socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
102
+ @socket.setsockopt(ZMQ::RCVHWM, @config[:rcv_hwm])
103
+ @socket.setsockopt(ZMQ::RCVTIMEO, @config[:rcv_timeo])
104
+ @socket.setsockopt(ZMQ::SNDTIMEO, @config[:snd_timeo])
105
+ spec = connection_specs.sort_by{rand}.first
106
+ @socket.connect(spec)
107
+ @socket
108
+ end
109
+
102
110
  def publish(app_env, key, data)
103
111
  info = pack_info(@sequence = next_fixnum(@sequence))
104
112
  parts = [app_env, key, data, info]
@@ -109,8 +117,6 @@ module LogjamAgent
109
117
  end
110
118
  end
111
119
 
112
- private
113
-
114
120
  def log_warning(message)
115
121
  LogjamAgent.error_handler.call ForwardingWarning.new(message)
116
122
  end
@@ -138,8 +144,10 @@ module LogjamAgent
138
144
  end
139
145
 
140
146
  def ping
141
- if @socket && !send_receive("ping", @app_env, "{}", NO_COMPRESSION)
142
- log_warning "failed to receive pong"
147
+ @socket_mutex.synchronize do
148
+ if @socket && !send_receive("ping", @app_env, "{}", NO_COMPRESSION)
149
+ log_warning "failed to receive pong"
150
+ end
143
151
  end
144
152
  end
145
153
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logjam_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2020-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake