serverengine 2.0.5-x86-mingw32 → 2.1.0-x86-mingw32

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: 26439e07fed354d0e3905cbff551f9aa50a5d674
4
- data.tar.gz: 35207be927ebee981432fd567ab2949c22ba3ce1
3
+ metadata.gz: 85e711e9acc8754486f54027c6889b07d3a7575b
4
+ data.tar.gz: e460eb40289f7e311d87150388d7fced1655bf27
5
5
  SHA512:
6
- metadata.gz: d309cd49d40c046b489f12d231955b37c3fea54b49aadd81a639b50fe27135ce9352a310e1e3bbdb8967446f3d9cde9176079a467808f68ba1aec20951b3e293
7
- data.tar.gz: 30cea237e564f012160ee11d5de801812318db0955e48a32c355056c5b207fb666d084e8973fb9cd538744266c27790546fc3f2e0bd63a855ca1c1bb31f816f4
6
+ metadata.gz: f2e2d0e71bc11bb1fa6b90324fa376d50b76e9c76ec46ad74da63c61d6de1cf035a311d8192faf759f40dd50c55461861264f66c104a97e69d10a5449422b81c
7
+ data.tar.gz: e28c44bf3dea2cb86d9dfa74a934fb33b6ec307ad6b1e005a4e76c174b7b0dfb5c54c2dcf2c24ce2a808f741c71c021d56b24468b81bf2c633a6af4eea93aed8
data/.travis.yml CHANGED
@@ -2,9 +2,10 @@ language: ruby
2
2
 
3
3
  rvm:
4
4
  - 2.1.10
5
- - 2.2.6
6
- - 2.3.3
7
- - 2.4.0
5
+ - 2.2.9
6
+ - 2.3.8
7
+ - 2.4.5
8
+ - 2.5.3
8
9
  - ruby-head
9
10
 
10
11
  branches:
data/Changelog CHANGED
@@ -1,3 +1,15 @@
1
+ 2018-11-14 version 2.1.0:
2
+
3
+ * Improve socket manager security
4
+
5
+ 2018-07-09 version 2.0.7:
6
+
7
+ * Add disable_sigdump option
8
+
9
+ 2018-02-09 version 2.0.6:
10
+
11
+ * Avoid thread error log in ruby 2.5
12
+
1
13
  2017-03-01 version 2.0.5:
2
14
 
3
15
  * Support SERVERENGINE_SOCKETMANAGER_SOCK_DIR environment variable to change
data/README.md CHANGED
@@ -319,7 +319,8 @@ Send `USR2` signal to reload configuration file.
319
319
  - **HUP:** immediate restart (available only when `worker_type` is "process")
320
320
  - **USR2:** reload config file and reopen log file
321
321
  - **INT:** detach process for live restarting (available only when `supervisor` and `enable_detach` parameters are true. otherwise graceful shutdown)
322
- - **CONT:** dump stacktrace and memory information to /tmp/sigdump-<pid>.log file
322
+ - **CONT:** dump stacktrace and memory information to /tmp/sigdump-<pid>.log file. This can be
323
+ disabled by including `disable_sigdump: true` in the configuration.
323
324
 
324
325
  Immediate shutdown and restart send SIGQUIT signal to worker processes which kills the processes.
325
326
  Graceful shutdown and restart call `Worker#stop` method and wait for completion of `Worker#run` method.
@@ -463,6 +464,7 @@ Available methods are different depending on `worker_type`. ServerEngine support
463
464
  - **daemonize** enables daemonize (default: false)
464
465
  - **pid_path** sets the path to pid file (default: don't create pid file)
465
466
  - **supervisor** enables supervisor if it's true (default: false)
467
+ - **disable_sigdump** disables the handling of the `SIGCONT` signal and dumping of the thread (default: false)
466
468
  - **daemon_process_name** changes process name ($0) of server or supervisor process
467
469
  - **chuser** changes execution user
468
470
  - **chgroup** changes execution group
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  require 'fcntl'
19
+ require 'serverengine/socket_manager'
19
20
 
20
21
  module ServerEngine
21
22
 
@@ -185,6 +186,7 @@ module ServerEngine
185
186
  @command_sender_pipe.binmode
186
187
  options[:in] = inpipe
187
188
  end
189
+ env['SERVERENGINE_SOCKETMANAGER_INTERNAL_TOKEN'] = SocketManager::INTERNAL_TOKEN
188
190
  pid = Process.spawn(env, *args, options)
189
191
  if @command_sender == "pipe"
190
192
  inpipe.close
@@ -70,6 +70,11 @@ module ServerEngine
70
70
  nil
71
71
  end
72
72
 
73
+ def dump
74
+ Sigdump.dump unless config[:disable_sigdump]
75
+ nil
76
+ end
77
+
73
78
  def install_signal_handlers
74
79
  s = self
75
80
  if @command_pipe
@@ -89,7 +94,7 @@ module ServerEngine
89
94
  when "DETACH"
90
95
  s.detach(true)
91
96
  when "DUMP"
92
- Sigdump.dump
97
+ s.dump
93
98
  end
94
99
  end
95
100
  end
@@ -104,7 +109,7 @@ module ServerEngine
104
109
  st.trap(@config[:signal_graceful_restart] || Signals::GRACEFUL_RESTART) { s.restart(true) }
105
110
  st.trap(@config[:signal_immediate_restart] || Signals::IMMEDIATE_RESTART) { s.restart(false) }
106
111
  st.trap(@config[:signal_reload] || Signals::RELOAD) { s.reload }
107
- st.trap(@config[:signal_dump] || Signals::DUMP) { Sigdump.dump }
112
+ st.trap(@config[:signal_dump] || Signals::DUMP) { s.dump }
108
113
  end
109
114
  end
110
115
  end
@@ -18,9 +18,18 @@
18
18
  require 'socket'
19
19
  require 'ipaddr'
20
20
  require 'time'
21
+ require 'securerandom'
22
+ require 'json'
23
+ require 'base64'
21
24
 
22
25
  module ServerEngine
23
26
  module SocketManager
27
+ # This token is used for communication between peers. If token is mismatched, messages will be discarded
28
+ INTERNAL_TOKEN = if ENV.has_key?('SERVERENGINE_SOCKETMANAGER_INTERNAL_TOKEN')
29
+ ENV['SERVERENGINE_SOCKETMANAGER_INTERNAL_TOKEN']
30
+ else
31
+ SecureRandom.hex
32
+ end
24
33
 
25
34
  class Client
26
35
  def initialize(path)
@@ -138,7 +147,10 @@ module ServerEngine
138
147
 
139
148
  def process_peer(peer)
140
149
  while true
141
- pid, method, bind, port = *SocketManager.recv_peer(peer)
150
+ res = SocketManager.recv_peer(peer)
151
+ return if res.nil?
152
+
153
+ pid, method, bind, port = *res
142
154
  begin
143
155
  send_socket(peer, pid, method, bind, port)
144
156
  rescue => e
@@ -151,15 +163,22 @@ module ServerEngine
151
163
  end
152
164
 
153
165
  def self.send_peer(peer, obj)
154
- data = Marshal.dump(obj)
166
+ data = [SocketManager::INTERNAL_TOKEN, Base64.strict_encode64(Marshal.dump(obj))]
167
+ data = JSON.generate(data)
155
168
  peer.write [data.bytesize].pack('N')
156
169
  peer.write data
157
170
  end
158
171
 
159
172
  def self.recv_peer(peer)
160
- len = peer.read(4).unpack('N').first
173
+ res = peer.read(4)
174
+ return nil if res.nil?
175
+
176
+ len = res.unpack('N').first
161
177
  data = peer.read(len)
162
- Marshal.load(data)
178
+ data = JSON.parse(data)
179
+ return nil if SocketManager::INTERNAL_TOKEN != data.first
180
+
181
+ Marshal.load(Base64.strict_decode64(data.last))
163
182
  end
164
183
 
165
184
  if ServerEngine.windows?
@@ -70,7 +70,12 @@ module ServerEngine
70
70
  # when client changed working directory
71
71
  path = File.expand_path(path)
72
72
 
73
- @server = UNIXServer.new(path)
73
+ begin
74
+ old_umask = File.umask(0077) # Protect unix socket from other users
75
+ @server = UNIXServer.new(path)
76
+ ensure
77
+ File.umask(old_umask)
78
+ end
74
79
 
75
80
  @thread = Thread.new do
76
81
  begin
@@ -96,7 +101,14 @@ module ServerEngine
96
101
  end
97
102
 
98
103
  def send_socket(peer, pid, method, bind, port)
99
- sock = send(method, bind, port) # calls listen_tcp or listen_udp
104
+ sock = case method
105
+ when :listen_tcp
106
+ listen_tcp(bind, port)
107
+ when :listen_udp
108
+ listen_udp(bind, port)
109
+ else
110
+ raise ArgumentError, "Unknown method: #{method.inspect}"
111
+ end
100
112
 
101
113
  SocketManager.send_peer(peer, nil)
102
114
 
@@ -148,6 +148,10 @@ module ServerEngine
148
148
  end
149
149
  end
150
150
 
151
+ def dump
152
+ _dump
153
+ end
154
+
151
155
  def install_signal_handlers
152
156
  s = self
153
157
  if @command_pipe
@@ -167,7 +171,7 @@ module ServerEngine
167
171
  when "DETACH"
168
172
  s.detach(true)
169
173
  when "DUMP"
170
- Sigdump.dump
174
+ s.dump
171
175
  end
172
176
  end
173
177
  end
@@ -179,7 +183,7 @@ module ServerEngine
179
183
  st.trap(Signals::IMMEDIATE_RESTART) { s.restart(false) }
180
184
  st.trap(Signals::RELOAD) { s.reload }
181
185
  st.trap(Signals::DETACH) { s.detach(true) }
182
- st.trap(Signals::DUMP) { Sigdump.dump }
186
+ st.trap(Signals::DUMP) { s.dump }
183
187
  end
184
188
  end
185
189
  end
@@ -1,3 +1,3 @@
1
1
  module ServerEngine
2
- VERSION = "2.0.5"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -54,6 +54,10 @@ module ServerEngine
54
54
  def after_start
55
55
  end
56
56
 
57
+ def dump
58
+ Sigdump.dump unless config[:disable_sigdump]
59
+ end
60
+
57
61
  def install_signal_handlers
58
62
  w = self
59
63
  SignalThread.new do |st|
@@ -69,7 +73,7 @@ module ServerEngine
69
73
  }
70
74
  st.trap(Signals::DETACH) { w.stop }
71
75
 
72
- st.trap(Signals::DUMP) { Sigdump.dump }
76
+ st.trap(Signals::DUMP) { w.dump }
73
77
  end
74
78
  end
75
79
 
@@ -77,5 +81,4 @@ module ServerEngine
77
81
  run
78
82
  end
79
83
  end
80
-
81
84
  end
data/serverengine.gemspec CHANGED
@@ -15,7 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
- gem.has_rdoc = false
19
18
 
20
19
  gem.required_ruby_version = ">= 2.1.0"
21
20
 
data/spec/daemon_spec.rb CHANGED
@@ -44,6 +44,10 @@ describe ServerEngine::Daemon do
44
44
  wait_for_stop
45
45
  test_state(:server_restart_immediate).should == 1
46
46
 
47
+ dm.dump
48
+ wait_for_stop
49
+ test_state(:server_dump).should == 1
50
+
47
51
  dm.stop(false)
48
52
  wait_for_stop
49
53
  test_state(:server_stop_immediate).should == 1
@@ -146,6 +146,11 @@ module TestServer
146
146
  incr_test_state :server_detach
147
147
  super
148
148
  end
149
+
150
+ def dump
151
+ incr_test_state :server_dump
152
+ super
153
+ end
149
154
  end
150
155
 
151
156
  module TestWorker
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverengine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.1.0
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2018-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sigdump
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.6.8
171
+ rubygems_version: 2.6.14.1
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: ServerEngine - multiprocess server framework