remote_syslog_sender 1.1.3 → 1.1.4

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
  SHA1:
3
- metadata.gz: 05d03966e485764b3f9a76b96a15d5bd3ed63185
4
- data.tar.gz: a0781e58be56ae8206b93e9c60f7fe9bef5654bd
3
+ metadata.gz: c16108731d2d7b6e31e5af7c7ece9e4eeee102f8
4
+ data.tar.gz: 486189b1bb483e7febc18cc678f7a95c7df589a4
5
5
  SHA512:
6
- metadata.gz: 4086fc64db33dc77af8eddc63c17822440ef83ef82b14cd2131ca424b9e40c57c86caca741e561aed41defbbef36d8952ab5c6dfdbfcce43888ab44bc5ab92a1
7
- data.tar.gz: 15ca1c0a228a16b1480bf5eeb1763487f5f0be02e998a5e454a0e24e9f92893851a501fde875237ef168e47d43a4f2bd0917e5510f6c94954bd16c9dea509d13
6
+ metadata.gz: 1decdb20cd350dd7bb3c5b25a1b0082479ec065854e1ffa9aa80f35658d766657ea0709d2ce4032f5ce69c2ec185606ada0079e09ecc5c1d4c80a85b3a9c85f6
7
+ data.tar.gz: e74dd3847e4ecb0cb63c77238d3fff45aec2798213e679c991c895a95ae21ce7fe28163569e89fc2f3fc331825e768b2c17cd3edc690522860ef5b80a3b0803e
@@ -16,9 +16,10 @@ module RemoteSyslogSender
16
16
  @ssl_method = options[:ssl_method] || 'TLSv1_2'
17
17
  @ca_file = options[:ca_file]
18
18
  @verify_mode = options[:verify_mode]
19
- @timeout = options[:timeout]
19
+ @timeout = options[:timeout] || 600
20
20
  @timeout_exception = !!options[:timeout_exception]
21
21
  @exponential_backoff = !!options[:exponential_backoff]
22
+ @connect_mutex = Mutex.new
22
23
 
23
24
  if [:SOL_SOCKET, :SO_KEEPALIVE, :IPPROTO_TCP, :TCP_KEEPIDLE].all? {|c| Socket.const_defined? c}
24
25
  @keep_alive = options[:keep_alive]
@@ -44,40 +45,40 @@ module RemoteSyslogSender
44
45
 
45
46
  def connect
46
47
  connect_retry_count = 0
47
- connect_retry_limit = 2
48
+ connect_retry_limit = 3
48
49
  connect_retry_interval = 1
49
- begin
50
- sock = TCPSocket.new(@remote_hostname, @remote_port)
51
-
52
- if @keep_alive
53
- sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
54
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPIDLE, @keep_alive_idle) if @keep_alive_idle
55
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPCNT, @keep_alive_cnt) if @keep_alive_cnt
56
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPINTVL, @keep_alive_intvl) if @keep_alive_intvl
57
- end
58
- if @tls
59
- require 'openssl'
60
- context = OpenSSL::SSL::SSLContext.new(@ssl_method)
61
- context.ca_file = @ca_file if @ca_file
62
- context.verify_mode = @verify_mode if @verify_mode
63
-
64
- @tcp_socket = sock
65
- @socket = OpenSSL::SSL::SSLSocket.new(sock, context)
66
- @socket.connect
67
- @socket.post_connection_check(@remote_hostname)
68
- raise "test" if connect_retry_count < 1
69
- raise "verification error" if @socket.verify_result != OpenSSL::X509::V_OK
70
- else
71
- @socket = sock
72
- end
73
- rescue => e
74
- close
75
- if connect_retry_count < connect_retry_limit
76
- sleep connect_retry_interval
77
- connect_retry_count += 1
78
- retry
79
- else
80
- raise
50
+ @connect_mutex.synchronize do
51
+ begin
52
+ @tcp_socket = TCPSocket.new(@remote_hostname, @remote_port)
53
+
54
+ if @keep_alive
55
+ @tcp_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
56
+ @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPIDLE, @keep_alive_idle) if @keep_alive_idle
57
+ @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPCNT, @keep_alive_cnt) if @keep_alive_cnt
58
+ @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPINTVL, @keep_alive_intvl) if @keep_alive_intvl
59
+ end
60
+ if @tls
61
+ require 'openssl'
62
+ context = OpenSSL::SSL::SSLContext.new(@ssl_method)
63
+ context.ca_file = @ca_file if @ca_file
64
+ context.verify_mode = @verify_mode if @verify_mode
65
+
66
+ @socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket, context)
67
+ @socket.connect
68
+ @socket.post_connection_check(@remote_hostname)
69
+ raise "verification error" if @socket.verify_result != OpenSSL::X509::V_OK
70
+ else
71
+ @socket = @tcp_socket
72
+ end
73
+ rescue
74
+ close
75
+ if connect_retry_count < connect_retry_limit
76
+ sleep connect_retry_interval
77
+ connect_retry_count += 1
78
+ retry
79
+ else
80
+ raise
81
+ end
81
82
  end
82
83
  end
83
84
  end
@@ -103,6 +104,12 @@ module RemoteSyslogSender
103
104
  result = @socket.__send__(method, payload)
104
105
  payload_size -= result
105
106
  payload.slice!(0, result) if payload_size > 0
107
+ rescue IO::WaitReadable
108
+ timeout_wait = @timeout - (get_time - start)
109
+ retry if IO.select([@socket], nil, nil, timeout_wait)
110
+
111
+ raise NonBlockingTimeout if @timeout_exception
112
+ break
106
113
  rescue IO::WaitWritable
107
114
  timeout_wait = @timeout - (get_time - start)
108
115
  retry if IO.select(nil, [@socket], nil, timeout_wait)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'remote_syslog_sender'
3
- s.version = '1.1.3'
3
+ s.version = '1.1.4'
4
4
  s.summary = "Message sender that sends directly to a remote syslog endpoint"
5
5
  s.description = "Message sender that sends directly to a remote syslog endpoint (Support UDP, TCP, TCP+TLS)"
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_syslog_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiro Hashidate