bayserver-docker-cgi 2.2.2 → 2.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eb12007ac5ff474ce860f5809ff065af555a64ef5eaf88007a7053c0e6991d5
4
- data.tar.gz: 79ec49ef0f447b6aaf0c7ee2f35171e35bdcd77a7cb97252c4801419783d98de
3
+ metadata.gz: b69f13e53289413270d966247cb5c22bab95b4fd81acd9c0cdfccb189627db6f
4
+ data.tar.gz: c3efa92676178b25626e5a4a4d57a19c48d308603914f92290d4e2ac1dcc5084
5
5
  SHA512:
6
- metadata.gz: ae783b21b39acdd9feae4c22d32f73c644fe51b3600c2cf99f9ce9053ec91d4fcbe090264b5caf33fdb32b1f36538a9bf927930151497bc1be283f166f91c18e
7
- data.tar.gz: e935d8206653665138d375adef086f4d2e68d95837cbfc3c28da7f31047dd44cfb00efc5ef9bcabc0ddd00fece6de4b9d25d6afe4d5e664a81ca135220e0c192
6
+ metadata.gz: b9f9784da221bd460e0885d5ef79bf05ab055fcd12717ffbb278d11cda4f2b2a3dd702e89be1569bf7a3c3e13ee4c79f2fe01dd99f102bdc870db73010525fab
7
+ data.tar.gz: 244042e90cbd62de5b5d21552e45a72085fdc6b54190138ed2f90053b443df65b6fbf29fe6c9603c5ec8f5d8167533685f4c65624ae11d43633c50cfba22e4b6
@@ -29,11 +29,12 @@ module Baykit
29
29
  include Baykit::BayServer::Taxi
30
30
 
31
31
  DEFAULT_PROC_READ_METHOD = Harbor::FILE_SEND_METHOD_TAXI
32
- DEFAULT_TIMEOUT_SEC = 60
32
+ DEFAULT_TIMEOUT_SEC = 0
33
33
 
34
34
  attr :interpreter
35
35
  attr :script_base
36
36
  attr :doc_root
37
+ attr :timeout_sec
37
38
 
38
39
  # Method to read stdin/stderr
39
40
  attr :proc_read_method
@@ -93,12 +94,13 @@ module Baykit
93
94
  when "taxi"
94
95
  @proc_read_method = Harbor::FILE_SEND_METHOD_TAXI
95
96
 
96
- when "timeout"
97
- @timeout_sec = int(kv.value)
98
-
99
97
  else
100
98
  raise ConfigException.new(kv.file_name, kv.line_no, BayMessage.get(:CFG_INVALID_PARAMETER_VALUE, kv.value))
101
99
  end
100
+
101
+ when "timeout"
102
+ @timeout_sec = kv.value.to_i
103
+
102
104
  else
103
105
  return super
104
106
  end
@@ -159,12 +161,12 @@ module Baykit
159
161
  case(@proc_read_method)
160
162
  when Harbor::FILE_SEND_METHOD_SELECT
161
163
  out_tp = PlainTransporter.new(false, bufsize)
162
- out_yat.init(tur, out_tp)
164
+ out_yat.init(tur, out_tp, handler)
163
165
  out_tp.init(tur.ship.agent.non_blocking_handler, handler.std_out[0], out_yat)
164
166
  out_tp.open_valve()
165
167
 
166
168
  err_tp = PlainTransporter.new(false, bufsize)
167
- err_yat.init(tur)
169
+ err_yat.init(tur, handler)
168
170
  err_tp.init(tur.ship.agent.non_blocking_handler, handler.std_err[0], err_yat)
169
171
  err_tp.open_valve()
170
172
 
@@ -181,27 +183,27 @@ module Baykit
181
183
  end
182
184
 
183
185
  out_tp = SpinReadTransporter.new(bufsize)
184
- out_yat.init(tur, out_tp)
186
+ out_yat.init(tur, out_tp, handler)
185
187
  out_tp.init(tur.ship.agent.spin_handler, out_yat, handler.std_out[0], -1, @timeout_sec, eof_checker)
186
188
  out_tp.open_valve()
187
189
 
188
190
  err_tp = SpinReadTransporter.new(bufsize)
189
- err_yat.init(tur)
191
+ err_yat.init(tur, handler)
190
192
  err_tp.init(tur.ship.agent.spin_handler, err_yat, handler.std_out[0], -1, @timeout_sec, eof_checker)
191
193
  err_tp.open_valve()
192
194
 
193
195
  when Harbor::FILE_SEND_METHOD_TAXI
194
- out_txi = ReadFileTaxi.new(bufsize)
195
- out_yat.init(tur, out_txi)
196
+ out_txi = ReadFileTaxi.new(tur.ship.agent.agent_id, bufsize)
197
+ out_yat.init(tur, out_txi, handler)
196
198
  out_txi.init(handler.std_out[0], out_yat)
197
- if !TaxiRunner.post(out_txi)
199
+ if !TaxiRunner.post(tur.ship.agent.agent_id, out_txi)
198
200
  raise HttpException.new(HttpStatus.SERVICE_UNAVAILABLE, "Taxi is busy!")
199
201
  end
200
202
 
201
- err_txi = ReadFileTaxi.new(bufsize)
202
- err_yat.init(tur)
203
+ err_txi = ReadFileTaxi.new(tur.ship.agent.agent_id, bufsize)
204
+ err_yat.init(tur, @timeout_sec)
203
205
  err_txi.init(handler.std_err[0], err_yat)
204
- if !TaxiRunner.post(err_txi)
206
+ if !TaxiRunner.post(tur.ship.agent.agent_id, err_txi)
205
207
  raise HttpException.new(HttpStatus.SERVICE_UNAVAILABLE, "Taxi is busy!")
206
208
  end
207
209
 
@@ -28,11 +28,14 @@ module Baykit
28
28
  attr :std_err
29
29
  attr :std_out_closed
30
30
  attr :std_err_closed
31
+ attr :last_access
31
32
 
32
33
  def initialize(cgi_docker, tur)
33
34
  @cgi_docker = cgi_docker
34
35
  @tour = tur
35
36
  @tour_id = tur.tour_id
37
+ @std_out_closed = true
38
+ @std_err_closed = true
36
39
  end
37
40
 
38
41
  ######################################################
@@ -45,10 +48,12 @@ module Baykit
45
48
  wrote_len = @std_in[1].write(buf[start, len])
46
49
  BayLog.debug("%s CGI:onReadReqContent: wrote=%d", tur, wrote_len)
47
50
  tur.req.consumed(Tour::TOUR_ID_NOCHECK, len)
51
+ access()
48
52
  end
49
53
 
50
54
  def on_end_content(tur)
51
55
  BayLog.trace("%s CGI:endReqContent", tur)
56
+ access()
52
57
  end
53
58
 
54
59
  def on_abort(tur)
@@ -92,7 +97,7 @@ module Baykit
92
97
 
93
98
  @std_out_closed = false
94
99
  @std_err_closed = false
95
-
100
+ access()
96
101
  end
97
102
 
98
103
  def std_out_closed()
@@ -109,13 +114,27 @@ module Baykit
109
114
  end
110
115
  end
111
116
 
117
+ def access()
118
+ @last_access = Time.now.to_i
119
+ end
120
+
121
+ def timed_out()
122
+ if @cgi_docker.timeout_sec <= 0
123
+ return false
124
+ end
125
+
126
+ duration_sec = Time.now.to_i - @last_access
127
+ BayLog.debug("%s Check CGI timeout: dur=%d, timeout=%d", @tour, duration_sec, @cgi_docker.timeout_sec)
128
+ return duration_sec > @cgi_docker.timeout_sec
129
+ end
130
+
112
131
  def process_finished()
132
+ BayLog.debug("%s CGI Process finished: pid=%s", @tour, @pid)
133
+
113
134
  pid, stat = Process.wait2(@pid)
135
+ print(stat)
114
136
 
115
137
  BayLog.debug("%s CGI Process finished: pid=%s code=%s", @tour, pid, stat.exitstatus)
116
- if pid == nil
117
- BayLog.error("Process not finished: %d", @pid)
118
- end
119
138
 
120
139
  begin
121
140
  if stat.exitstatus != 0
@@ -14,6 +14,7 @@ module Baykit
14
14
 
15
15
  attr :tour
16
16
  attr :tour_id
17
+ attr :handler
17
18
 
18
19
  def initialize
19
20
  super
@@ -31,6 +32,7 @@ module Baykit
31
32
  def reset()
32
33
  @tour = nil
33
34
  @tour_id = 0
35
+ @timeout_sec = 0
34
36
  end
35
37
 
36
38
  ######################################################
@@ -49,28 +51,29 @@ module Baykit
49
51
  end
50
52
 
51
53
  def notify_eof()
52
- BayLog.debug("%s CGI StdErr: EOF\\(^o^)/", self)
54
+ BayLog.debug("%s stderr EOF\\(^o^)/", @tour)
53
55
  return NextSocketAction::CLOSE
54
56
  end
55
57
 
56
58
  def notify_close()
57
- BayLog.debug("%s CGI StdErr: notifyClose", self)
59
+ BayLog.debug("%s stderr notifyClose", @tour)
58
60
  @tour.req.content_handler.std_err_closed()
59
61
  end
60
62
 
61
- def check_timeout(duration)
62
- BayLog.warn("%s invalid timeout check", self)
63
- return false
63
+ def check_timeout(duration_sec)
64
+ BayLog.debug("%s stderr Check timeout: dur=%d, timeout=%d", @tour, duration_sec, @timeout_sec)
65
+ return @handler.timed_out()
64
66
  end
65
67
 
66
68
  ######################################################
67
69
  # Custom methods
68
70
  ######################################################
69
71
 
70
- def init(tur)
72
+ def init(tur, handler)
71
73
  init_yacht()
72
74
  @tour = tur
73
75
  @tour_id = tur.tour_id
76
+ @handler = handler
74
77
  end
75
78
  end
76
79
  end
@@ -19,6 +19,7 @@ module Baykit
19
19
 
20
20
  attr :remain
21
21
  attr :header_reading
22
+ attr :handler
22
23
 
23
24
  def initialize
24
25
  super
@@ -39,6 +40,7 @@ module Baykit
39
40
  @tour_id = 0
40
41
  @header_reading = true
41
42
  @remain = ""
43
+ @handler = nil
42
44
  end
43
45
 
44
46
  ######################################################
@@ -112,6 +114,7 @@ module Baykit
112
114
  end
113
115
  end
114
116
 
117
+ @handler.access()
115
118
  if available
116
119
  return NextSocketAction::CONTINUE;
117
120
  else
@@ -121,17 +124,25 @@ module Baykit
121
124
  end
122
125
 
123
126
  def notify_eof()
124
- BayLog.debug("%s CGI StdOut: EOF(^o^)", self)
127
+ BayLog.debug("%s stdout EOF(^o^)", @tour)
125
128
  return NextSocketAction::CLOSE
126
129
  end
127
130
 
128
131
  def notify_close()
129
- BayLog.debug("%s CGI StdOut: notifyClose", self)
132
+ BayLog.debug("%s stdout notifyClose", @tour)
130
133
  @tour.req.content_handler.std_out_closed()
131
134
  end
132
135
 
133
- def check_timeout(duration)
134
- BayLog.warn("%s invalid timeout check", self)
136
+ def check_timeout(duration_sec)
137
+ BayLog.debug("%s Check StdOut timeout: dur=%d", @tour, duration_sec)
138
+
139
+ if @handler.timed_out()
140
+ # Kill cgi process instead of handing timeout
141
+ BayLog.warn("%s Kill process!: %d", @tour, @handler.pid)
142
+ Process.kill("KILL", @handler.pid)
143
+ return true
144
+ end
145
+
135
146
  return false
136
147
  end
137
148
 
@@ -139,8 +150,9 @@ module Baykit
139
150
  # Custom methods
140
151
  ######################################################
141
152
 
142
- def init(tur, valve)
153
+ def init(tur, valve, handler)
143
154
  init_yacht()
155
+ @handler = handler
144
156
  @tour = tur
145
157
  @tour_id = tur.tour_id
146
158
  tur.res.set_consume_listener do |len, resume|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bayserver-docker-cgi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michisuke-P
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-30 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bayserver-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.2
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.2
26
+ version: 2.3.0
27
27
  description: BayServer is one of the high-speed web servers. It operates as a single-threaded,
28
28
  asynchronous server, which makes it exceptionally fast. It also supports multi-core
29
29
  processors, harnessing the full potential of the CPU's capabilities.