tep 0.11.9 → 0.11.11

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: 82c269cf0ea0f3d9fa48c4eb2eb9c74ab91e6b503698713171ad45ce18a7c737
4
- data.tar.gz: 8624fd74d1c1e183a511c73dc3b65d45d32d3d721787a727b019ac6cd661eb6a
3
+ metadata.gz: e68ca09c2615377ed3677af21d535cd5fa62e2c139cb7072dc5f7a871a01aec3
4
+ data.tar.gz: 1397c35788be0cefed0bc1b064d149a2ccf38e2aa9fc48909146f127941ad32e
5
5
  SHA512:
6
- metadata.gz: 05456c12d7608845efeaafb6d1cd2f64b48fb54f70aa11033fed32027d0a4fab70d6a3ee223bc64091ebce3d8e561e23995a188aae060bc9a7f68d1f087be264
7
- data.tar.gz: df4bc58f06c7959603c88b4cd0bde44a4ee3b3773f910acbdc4454997b33628f5d21b7a501e6df8a7c02b6dcc34952694f1842bae51aee131584f03b9b08318e
6
+ metadata.gz: bb69a5448d4c4f8edcd0b0733bdf6b4f10d19099eef08681e41dcfcc22474b2f160729414b4d58861b15d68e1ce1d7b83651e599dfc584cda313a327b260212a
7
+ data.tar.gz: d6f9efce82df127514e67d81edb1bcc2f90cb672e9e036fede7b0dd66e494a5d9de412115083c2965a1e6b9dacd95168361481c697ee7fce8a250afabc8d8211
data/bin/tep CHANGED
@@ -2060,13 +2060,26 @@ def resolve_ext_o(entry, entries, env_var)
2060
2060
  fatal("ext '#{entry["name"]}' needs #{missing} — install its -dev headers")
2061
2061
  end
2062
2062
 
2063
+ # The cached object is keyed by what it was built from: the source
2064
+ # bytes and the compile flags. The directory used to be the checkout's
2065
+ # basename alone with an mtime check, so two trees with the same name
2066
+ # (a dev checkout and an app's vendored copy are both `tep`) shared a
2067
+ # slot, and whichever compiled last won as long as its object was newer
2068
+ # than the other tree's source. The result linked cleanly and returned
2069
+ # wrong data at run time.
2070
+ require "digest"
2071
+ key = Digest::SHA256.hexdigest(File.binread(src) + "\0" + cflags.join("\0"))[0, 16]
2063
2072
  cache = File.join(ENV["HOME"] || Dir.tmpdir, ".cache", "tep", "ext", File.basename(REPO_ROOT))
2064
2073
  FileUtils.mkdir_p(cache)
2065
- out = File.join(cache, File.basename(prebuilt))
2066
- return out if File.exist?(out) && File.mtime(out) >= File.mtime(src)
2074
+ out = File.join(cache, File.basename(prebuilt, ".o") + "-" + key + ".o")
2075
+ return out if File.exist?(out)
2067
2076
 
2068
2077
  warn "[tep] building ext '#{entry["name"]}' on demand (#{entry["source"]})"
2069
- if system(ENV.fetch("CC", "cc"), *cflags, "-c", src, "-o", out) && File.exist?(out)
2078
+ # Compile to a private name and rename, so a concurrent build never
2079
+ # links a half-written object.
2080
+ tmp = out + ".#{Process.pid}.tmp"
2081
+ if system(ENV.fetch("CC", "cc"), *cflags, "-c", src, "-o", tmp) && File.exist?(tmp)
2082
+ File.rename(tmp, out)
2070
2083
  out
2071
2084
  elsif entry["optional"]
2072
2085
  warn "[tep] optional ext '#{entry["name"]}' failed to build — disabling"
data/lib/tep/pg.rb CHANGED
@@ -1095,9 +1095,8 @@ module PG
1095
1095
  @free.push(c)
1096
1096
  if @waiter_idxs.length > 0
1097
1097
  widx = @waiter_idxs.delete_at(0)
1098
- # wake_at = -1 makes the fiber the "earliest due" in the
1099
- # next tick's pick (the tick comparator chooses the lowest
1100
- # wake_at among the time-due set, so -1 always wins).
1098
+ # wake_at = -1 marks the fiber due: the next tick's
1099
+ # resume_ready pass picks it up with the other due fibers.
1101
1100
  Tep::APP.sched_wake_at[widx] = -1
1102
1101
  end
1103
1102
  0
data/lib/tep/scheduler.rb CHANGED
@@ -45,19 +45,51 @@ module Tep
45
45
  READ = 1
46
46
  WRITE = 2
47
47
 
48
+ # Register `f` with the scheduler. Reuses the first dead slot if
49
+ # there is one, else appends. Reuse matters under connection churn:
50
+ # tick() only reclaims dead slots at the TAIL, and a fiber-per-
51
+ # connection server always has a live fiber there (the accept
52
+ # fiber, or the newest connection), so without reuse every closed
53
+ # connection leaves a dead slot -- and its mmap'd fiber stack --
54
+ # behind forever, and every poll_round walks all of them. Live
55
+ # slots never move, so indices captured across Fiber.yield (pg.rb's
56
+ # PG::Pool @waiter_idxs) stay valid.
48
57
  def self.spawn_fiber(f)
49
- Tep::APP.sched_fibers.push(Tep::FiberSlot.new(f))
50
- Tep::APP.sched_wake_at.push(-1)
51
- Tep::APP.sched_io_fd.push(-1)
52
- Tep::APP.sched_io_mode.push(0)
53
- Tep::APP.sched_io_ready.push(0)
58
+ idx = Scheduler.free_slot
59
+ if idx < 0
60
+ Tep::APP.sched_fibers.push(Tep::FiberSlot.new(f))
61
+ Tep::APP.sched_wake_at.push(-1)
62
+ Tep::APP.sched_io_fd.push(-1)
63
+ Tep::APP.sched_io_mode.push(0)
64
+ Tep::APP.sched_io_ready.push(0)
65
+ else
66
+ Tep::APP.sched_fibers[idx] = Tep::FiberSlot.new(f)
67
+ Tep::APP.sched_wake_at[idx] = -1
68
+ Tep::APP.sched_io_fd[idx] = -1
69
+ Tep::APP.sched_io_mode[idx] = 0
70
+ Tep::APP.sched_io_ready[idx] = 0
71
+ end
54
72
  f
55
73
  end
56
74
 
75
+ # Index of the first slot whose fiber has finished, or -1.
76
+ def self.free_slot
77
+ i = 0
78
+ n = Tep::APP.sched_fibers.length
79
+ while i < n
80
+ if !Tep::APP.sched_fibers[i].f.alive?
81
+ return i
82
+ end
83
+ i += 1
84
+ end
85
+ -1
86
+ end
87
+
57
88
  # One scheduler pass. If any fibers are parked on I/O, build a
58
89
  # poll set, run poll(2) for up to `poll_timeout_ms`, and mark
59
- # ready ones. Then resume the soonest-due fiber whose wake_at
60
- # is <= now. Returns true if it resumed something.
90
+ # ready ones. Then resume EVERY fiber whose wake_at is <= now, in
91
+ # slot order (see resume_ready). Returns true if it resumed
92
+ # something.
61
93
  #
62
94
  # If a fiber is already time-due (wake_at <= now -- e.g. a newly
63
95
  # spawned fiber with wake_at=-1, or a fiber that just called
@@ -69,15 +101,22 @@ module Tep
69
101
  # each "hand off to the freshly-spawned fiber" step costs a full
70
102
  # poll-timeout's worth of latency.
71
103
  def self.tick(poll_timeout_ms)
72
- # Reclaim trailing dead slots. Without this, the parallel
73
- # arrays grow once per accepted connection and never shrink --
74
- # a slow leak and per-tick iteration tax in a long-running
75
- # Scheduled server. Tail-only (stop at first alive) is
76
- # deliberate: it keeps every surviving slot's index stable,
77
- # so external captures of sched_current held across Fiber.yield
78
- # (e.g. pg.rb's PG::Pool @waiter_idxs) stay valid. Middle
79
- # dead slots aren't reclaimed until the tail catches up; for
80
- # FIFO request lifecycles that's the common case.
104
+ Scheduler.reclaim_tail
105
+ ms = poll_timeout_ms
106
+ if Scheduler.any_time_ready
107
+ ms = 0
108
+ end
109
+ Scheduler.poll_round(ms)
110
+ Scheduler.resume_ready > 0
111
+ end
112
+
113
+ # Reclaim trailing dead slots so the parallel arrays shrink back
114
+ # when the youngest fibers finish. Tail-only (stop at first alive)
115
+ # is deliberate: it keeps every surviving slot's index stable, so
116
+ # external captures of sched_current held across Fiber.yield (e.g.
117
+ # pg.rb's PG::Pool @waiter_idxs) stay valid. Dead slots in the
118
+ # middle are recycled by spawn_fiber instead.
119
+ def self.reclaim_tail
81
120
  i = Tep::APP.sched_fibers.length - 1
82
121
  while i >= 0 && !Tep::APP.sched_fibers[i].f.alive?
83
122
  Tep::APP.sched_fibers.delete_at(i)
@@ -87,33 +126,41 @@ module Tep
87
126
  Tep::APP.sched_io_ready.delete_at(i)
88
127
  i -= 1
89
128
  end
129
+ 0
130
+ end
90
131
 
91
- ms = poll_timeout_ms
92
- if Scheduler.any_time_ready
93
- ms = 0
94
- end
95
- Scheduler.poll_round(ms)
96
-
97
- now = Time.now.to_i
98
- best = -1
132
+ # Resume every due fiber (wake_at <= now -- which poll_round just
133
+ # set on the I/O-ready ones) once, in slot order. Returns how many
134
+ # were resumed.
135
+ #
136
+ # One resume per due fiber per pass is what keeps the scheduler
137
+ # fair. The earlier shape resumed only the single lowest-wake_at
138
+ # fiber per tick, and wake_at has whole-second resolution: every
139
+ # fiber readied within the same second tied, the lowest slot won
140
+ # the tie, and a keep-alive client that pipelines its next request
141
+ # straight away is readied again before anyone else runs -- so a
142
+ # few low-slot connections monopolised the worker and the rest
143
+ # stalled until the clock ticked over (max latency pinned at
144
+ # exactly 1s under load, p50 well under 1ms).
145
+ #
146
+ # `n` is captured before the loop: a resumed fiber may spawn (slot
147
+ # reuse or append); appended ones run next pass.
148
+ def self.resume_ready
149
+ now = Time.now.to_i
150
+ resumed = 0
99
151
  i = 0
100
152
  n = Tep::APP.sched_fibers.length
101
153
  while i < n
102
154
  if Tep::APP.sched_fibers[i].f.alive? && Tep::APP.sched_wake_at[i] <= now
103
- if best < 0 || Tep::APP.sched_wake_at[i] < Tep::APP.sched_wake_at[best]
104
- best = i
105
- end
155
+ Tep::APP.sched_current = i
156
+ Tep::APP.sched_wake_at[i] = -1
157
+ Tep::APP.sched_fibers[i].f.resume
158
+ Tep::APP.sched_current = -1
159
+ resumed += 1
106
160
  end
107
161
  i += 1
108
162
  end
109
- if best < 0
110
- return false
111
- end
112
- Tep::APP.sched_current = best
113
- Tep::APP.sched_wake_at[best] = -1
114
- Tep::APP.sched_fibers[best].f.resume
115
- Tep::APP.sched_current = -1
116
- true
163
+ resumed
117
164
  end
118
165
 
119
166
  # Build poll set from parked-on-I/O fibers, call poll(2), and
@@ -164,8 +211,14 @@ module Tep
164
211
  # Pure non-blocking; no poll() wait between passes.
165
212
  def self.run_until_empty
166
213
  n = 0
167
- while Scheduler.tick(0)
168
- n += 1
214
+ while true
215
+ Scheduler.reclaim_tail
216
+ Scheduler.poll_round(0)
217
+ r = Scheduler.resume_ready
218
+ if r == 0
219
+ return n
220
+ end
221
+ n += r
169
222
  end
170
223
  n
171
224
  end
data/lib/tep/shell.rb CHANGED
@@ -41,12 +41,20 @@ module Tep
41
41
  # silently return ""); we rescue here to preserve this helper's
42
42
  # never-raise contract -- a handler reading /proc should get "" for
43
43
  # an absent file, not a 502'd worker.
44
+ #
45
+ # The result goes through a local rather than being the begin/rescue
46
+ # expression's own value: at spinel 2026.10.25 a method whose value is
47
+ # `begin File.read(path) rescue "" end` hands back its ARGUMENT when
48
+ # the caller pushes the result onto a String array (broke
49
+ # Tep::Parallel#map_processes).
44
50
  def self.read(path)
51
+ out = ""
45
52
  begin
46
- File.read(path)
53
+ out = File.read(path)
47
54
  rescue => e
48
- ""
55
+ out = ""
49
56
  end
57
+ out
50
58
  end
51
59
 
52
60
  # Bounded read: slice after the fact. The cap is mostly a
data/lib/tep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tep
2
- VERSION = "0.11.9"
2
+ VERSION = "0.11.11"
3
3
  end
data/lib/tep.rb CHANGED
@@ -255,7 +255,7 @@ module Tep
255
255
  _tep_seed_sess.get("a")
256
256
  _tep_seed_sess.has?("a")
257
257
  _tep_seed_res.start_stream(Streamer.new)
258
- _tep_seed_stream = Stream.new(0)
258
+ _tep_seed_stream = Stream.new(-1)
259
259
  _tep_seed_res.streamer.pump(_tep_seed_stream)
260
260
  _tep_seed_stream.write("") # pin the parameter type to :str
261
261
  Tep.h("") # pin Tep.h(s)'s param to :str
@@ -265,7 +265,7 @@ module Tep
265
265
  Tep::Multipart.parse("", "")
266
266
  Tep::Multipart.extract_boundary("")
267
267
  Tep::Multipart.extract_field_name("")
268
- _tep_seed_res.start_websocket("", Tep::WebSocket::Driver.new(0))
268
+ _tep_seed_res.start_websocket("", Tep::WebSocket::Driver.new(-1))
269
269
 
270
270
  # AuthOAuth2 type-seeding. Every public cmeth needs at least one
271
271
  # top-level call so spinel locks the param C types in compile
@@ -782,7 +782,7 @@ module Tep
782
782
  _tep_seed_llm_state.acc = ""
783
783
  _tep_seed_llm_state.leftover = ""
784
784
  _tep_seed_llm_state.done = false
785
- _tep_seed_llm_stream = Tep::Stream.new(0)
785
+ _tep_seed_llm_stream = Tep::Stream.new(-1)
786
786
  Tep::Llm.consume_sse_events(_tep_seed_llm_stream, _tep_seed_llm_state)
787
787
  Tep::Llm.dechunk_consume("")
788
788
  Tep::Llm.dechunk_leftover("")
@@ -822,7 +822,7 @@ module Tep
822
822
  _tep_seed_ws_event.code = 0
823
823
  _tep_seed_ws_event.reason = ""
824
824
  _tep_seed_ws_handler.handle_event(_tep_seed_ws_event)
825
- _tep_seed_ws_drv = Tep::WebSocket::Driver.new(0)
825
+ _tep_seed_ws_drv = Tep::WebSocket::Driver.new(-1)
826
826
  _tep_seed_ws_drv.set_max_frame_size(0)
827
827
  _tep_seed_ws_drv.set_subprotocol("")
828
828
  _tep_seed_ws_drv.set_on_open(_tep_seed_ws_handler)
@@ -0,0 +1,29 @@
1
+ require_relative "helper"
2
+ require "socket"
3
+
4
+ # The boot-time type seeds used to build a Stream and two WebSocket
5
+ # drivers on descriptor 0 and write test frames to it. With a socket on
6
+ # stdin those 54 bytes reached the peer, and once an unread socket
7
+ # filled, a later start blocked before serving (#283).
8
+ class TestBootSeedStdin < Minitest::Test
9
+ def test_start_writes_nothing_to_a_socket_on_stdin
10
+ tmp = Dir.mktmpdir("tep-seed-stdin")
11
+ src = File.join(tmp, "app.rb")
12
+ File.write(src, "require \"sinatra\"\nget \"/\" do\n \"hi\"\nend\n")
13
+ bin = File.join(tmp, "app")
14
+ TepHarness.build_with_retry("#{TepHarness::TEP_BIN} build #{src} -o #{bin}", "tep build seed stdin app")
15
+ ours, theirs = UNIXSocket.pair
16
+ port = TepHarness.next_port
17
+ pid = Process.spawn(bin, "-p", port.to_s, "-q", in: theirs,
18
+ out: File.join(tmp, "app.log"), err: [:child, :out], pgroup: true)
19
+ theirs.close
20
+ TepHarness.wait_for_port(port, tmp: tmp, pid: pid)
21
+ TepHarness.reap(pid)
22
+ pid = nil
23
+ assert_equal "", ours.read, "the app wrote to its stdin socket at start"
24
+ ensure
25
+ TepHarness.reap(pid) if pid
26
+ ours&.close
27
+ FileUtils.rm_rf(tmp) if tmp
28
+ end
29
+ end
@@ -0,0 +1,81 @@
1
+ require_relative "helper"
2
+ require "net/http"
3
+
4
+ # `tep build` compiles the optional native helpers (sqlite, pg) on demand
5
+ # into ~/.cache/tep/ext/<checkout basename>/. The slot used to be keyed by
6
+ # that basename plus an mtime check, so another tree with the same name
7
+ # could leave an object there that this tree then linked: it built fine
8
+ # and SQLite queries returned nothing. The object is now keyed by the
9
+ # source bytes and compile flags.
10
+ class TestExtCache < Minitest::Test
11
+ REPO = File.expand_path("..", __dir__)
12
+ APP = <<~'RB'
13
+ require "sinatra"
14
+ get "/count" do
15
+ db = Tep::SQLite.new
16
+ db.open(ENV.fetch("DB_PATH", "/tmp/unset.db"))
17
+ db.exec("CREATE TABLE n (id INTEGER PRIMARY KEY, b TEXT)")
18
+ db.exec("INSERT INTO n (b) VALUES ('x')")
19
+ db.exec("INSERT INTO n (b) VALUES ('y')")
20
+ "count=" + db.first_int("SELECT COUNT(*) FROM n WHERE id > ?", "0").to_s
21
+ end
22
+ RB
23
+
24
+ def setup
25
+ skip "TEP_SQLITE_O set; the cache is bypassed" unless ENV["TEP_SQLITE_O"].to_s.empty?
26
+ @tmp = Dir.mktmpdir("tep-extcache")
27
+ @home = File.join(@tmp, "home")
28
+ # A dev checkout has `make helper`s prebuilt lib/tep/tep_sqlite.o, which
29
+ # bypasses the cache. Build from a copy without it, as an installed gem
30
+ # or an app-vendored tep does.
31
+ @tree = File.join(@tmp, "tep")
32
+ FileUtils.mkdir_p(@tree)
33
+ FileUtils.cp_r([File.join(REPO, "bin"), File.join(REPO, "lib"), File.join(REPO, "spinel-ext.json")], @tree)
34
+ FileUtils.rm_f(Dir[File.join(@tree, "lib", "tep", "tep_{sqlite,pg}.o")])
35
+ @slot = File.join(@home, ".cache", "tep", "ext", "tep")
36
+ FileUtils.mkdir_p(@slot)
37
+ @src = File.join(@tmp, "app.rb")
38
+ File.write(@src, APP)
39
+ end
40
+
41
+ def teardown
42
+ TepHarness.reap(@pid) if @pid
43
+ FileUtils.rm_rf(@tmp) if @tmp
44
+ end
45
+
46
+ def build(bin)
47
+ out = `HOME=#{@home} #{File.join(@tree, "bin", "tep")} build #{@src} -o #{bin} 2>&1`
48
+ assert $?.success?, "tep build failed:\n#{out}"
49
+ out
50
+ end
51
+
52
+ def test_foreign_object_in_the_slot_is_not_linked
53
+ # What another same-named tree would have left behind under the old
54
+ # scheme: an object at the unkeyed name, newer than our source. This
55
+ # one defines nothing, so linking it cannot produce a working binary.
56
+ decoy_c = File.join(@tmp, "decoy.c")
57
+ File.write(decoy_c, "int tep_decoy_unused;\n")
58
+ decoy = File.join(@slot, "tep_sqlite.o")
59
+ assert system("cc", "-c", decoy_c, "-o", decoy)
60
+ File.utime(Time.now + 3600, Time.now + 3600, decoy)
61
+
62
+ bin = File.join(@tmp, "app")
63
+ build(bin)
64
+
65
+ keyed = Dir[File.join(@slot, "tep_sqlite-*.o")]
66
+ assert_equal 1, keyed.length, "expected one content-keyed object, got #{Dir[File.join(@slot, '*')].inspect}"
67
+ assert_match(/tep_sqlite-\h{16}\.o\z/, keyed[0])
68
+
69
+ @port = TepHarness.next_port
70
+ @pid = Process.spawn({ "DB_PATH" => File.join(@tmp, "t.db") }, bin, "-p", @port.to_s, "-q",
71
+ out: File.join(@tmp, "app.log"), err: [:child, :out], pgroup: true)
72
+ TepHarness.wait_for_port(@port, tmp: @tmp, pid: @pid)
73
+ assert_equal "count=2", Net::HTTP.get(URI("http://127.0.0.1:#{@port}/count"))
74
+
75
+ # A second build reuses the keyed object.
76
+ before = File.mtime(keyed[0])
77
+ out = build(File.join(@tmp, "app2"))
78
+ refute_match(/building ext 'sqlite'/, out)
79
+ assert_equal before, File.mtime(keyed[0])
80
+ end
81
+ end
@@ -151,3 +151,67 @@ class TestScheduler < TepTest
151
151
  assert_match(/elapsed=[12]/, res.body)
152
152
  end
153
153
  end
154
+
155
+ # Scheduler fairness, exercised under Tep::Server::Scheduled (the
156
+ # prefork-handler variant above SIGSEGVs; here the handler already runs
157
+ # inside a scheduler fiber, and spawning more from it is the shape the
158
+ # accept loop uses).
159
+ class TestSchedulerFairness < TepTest
160
+ app_source <<~RB
161
+ require 'sinatra'
162
+ set :scheduler, :scheduled
163
+
164
+ class Trail
165
+ attr_accessor :s
166
+ def initialize
167
+ @s = ""
168
+ end
169
+ end
170
+
171
+ # Appends its name to the shared trail once per resume, `count`
172
+ # times, yielding plainly (wake_at stays -1 = due again next pass).
173
+ class Hopper
174
+ attr_accessor :fiber, :name, :trail, :remaining
175
+ def initialize(name, trail, count)
176
+ @name = name
177
+ @trail = trail
178
+ @remaining = count
179
+ @fiber = Fiber.new { run }
180
+ end
181
+ def run
182
+ while @remaining > 0
183
+ @trail.s = @trail.s + @name
184
+ @remaining -= 1
185
+ Fiber.yield
186
+ end
187
+ end
188
+ end
189
+
190
+ get '/round_robin' do
191
+ t = Trail.new
192
+ a = Hopper.new("A", t, 2)
193
+ b = Hopper.new("B", t, 2)
194
+ c = Hopper.new("C", t, 2)
195
+ Tep::Scheduler.spawn_fiber(a.fiber)
196
+ Tep::Scheduler.spawn_fiber(b.fiber)
197
+ Tep::Scheduler.spawn_fiber(c.fiber)
198
+ # Hand the scheduler a few passes so the hoppers get to run.
199
+ Tep::Scheduler.pause(0)
200
+ Tep::Scheduler.pause(0)
201
+ Tep::Scheduler.pause(0)
202
+ t.s
203
+ end
204
+ RB
205
+
206
+ def test_due_fibers_are_resumed_round_robin
207
+ res = get("/round_robin")
208
+ assert_equal "200", res.code
209
+ trail = res.body
210
+ assert_equal 6, trail.length, "trail=#{trail}"
211
+ # Each hopper runs once before any runs twice. The old picker
212
+ # resumed only the lowest slot among equally-due fibers per tick,
213
+ # which ran A to completion before B ever started ("AABBCC").
214
+ assert_equal %w[A B C], trail[0, 3].chars.sort, "trail=#{trail}"
215
+ assert_equal %w[A B C], trail[3, 3].chars.sort, "trail=#{trail}"
216
+ end
217
+ end
@@ -30,6 +30,10 @@ class TestServerScheduled < TepTest
30
30
  post "/echo_body" do
31
31
  request.body
32
32
  end
33
+
34
+ get "/sched_slots" do
35
+ Tep::APP.sched_fibers.length.to_s
36
+ end
33
37
  RB
34
38
 
35
39
  def test_basic_get_through_scheduler
@@ -91,4 +95,26 @@ class TestServerScheduled < TepTest
91
95
  assert_equal "pong", r2.body
92
96
  end
93
97
  end
98
+
99
+ def test_connection_churn_does_not_grow_scheduler_slots
100
+ # Overlapping connections: open the next one before closing the
101
+ # previous, so a live connection fiber always sits at the tail of
102
+ # the scheduler's slot arrays. Tail-only reclaim can't free the
103
+ # dead slots behind it; without slot reuse every closed connection
104
+ # leaves one behind (plus its fiber stack) for the worker's life.
105
+ prev = nil
106
+ 60.times do
107
+ h = Net::HTTP.new("127.0.0.1", @port)
108
+ h.read_timeout = 3
109
+ h.start
110
+ assert_equal "pong", h.get("/ping").body
111
+ prev.finish if prev
112
+ prev = h
113
+ end
114
+ slots = get("/sched_slots").body.to_i
115
+ prev.finish
116
+ # accept fiber + the two overlapping connections + this request's.
117
+ assert_operator slots, :<=, 8,
118
+ "scheduler kept #{slots} slots after 60 churned connections"
119
+ end
94
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.9
4
+ version: 0.11.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ori Pekelman
@@ -183,6 +183,7 @@ files:
183
183
  - test/test_auth.rb
184
184
  - test/test_auth_oauth2.rb
185
185
  - test/test_auth_session_cookie.rb
186
+ - test/test_boot_seed_stdin.rb
186
187
  - test/test_broadcast.rb
187
188
  - test/test_broadcast_pg.rb
188
189
  - test/test_cache.rb
@@ -191,6 +192,7 @@ files:
191
192
  - test/test_erb.rb
192
193
  - test/test_erb_ivars.rb
193
194
  - test/test_events.rb
195
+ - test/test_ext_cache.rb
194
196
  - test/test_filters.rb
195
197
  - test/test_geohash_example.rb
196
198
  - test/test_http.rb