tep 0.11.11 → 0.11.12
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 +4 -4
- data/lib/tep/server_scheduled.rb +14 -2
- data/lib/tep/version.rb +1 -1
- data/test/test_server_scheduled.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d48ebe0e98b19848548906bca9b1da41c8d98bc18e01b76299dabf50a8287ecb
|
|
4
|
+
data.tar.gz: c52abc13d471eb8c1d7fa089e33b49ec707b18270053e67105cd23e516d9afb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 883c5f954aa6f7d5db7b3d58eee2bca7b57e4a4ee63507d01b18ee80f27047347d29610444487dac72c82559b5bc2501530b12cd1c9735bd47cf9c2a0477ccb0
|
|
7
|
+
data.tar.gz: b1afdff3218b4c70b3d387f03dc0e1c8b172264435f349a321def1fe283ced5866a295381daa16675d6e39322310f11ee4b39f1e59106be66ad0dea31b4da905
|
data/lib/tep/server_scheduled.rb
CHANGED
|
@@ -134,11 +134,23 @@ module Tep
|
|
|
134
134
|
next
|
|
135
135
|
end
|
|
136
136
|
Sock.sphttp_set_nonblock(client)
|
|
137
|
-
|
|
138
|
-
Tep::Scheduler.spawn_fiber(conn)
|
|
137
|
+
Tep::Server::Scheduled.spawn_connection(client)
|
|
139
138
|
end
|
|
140
139
|
end
|
|
141
140
|
|
|
141
|
+
# One fiber per accepted connection. A method of its own so the
|
|
142
|
+
# block closes over THIS call's `client`. Built inline in
|
|
143
|
+
# accept_loop it captured the loop's variable, which the next
|
|
144
|
+
# accept overwrites -- and the scheduler resumes the accept fiber
|
|
145
|
+
# (slot 0) before a fiber appended on the previous pass has
|
|
146
|
+
# started. Two fibers then served the newer fd and the older
|
|
147
|
+
# connection was never read.
|
|
148
|
+
def self.spawn_connection(client)
|
|
149
|
+
conn = Fiber.new { Tep::Server::Scheduled.handle_connection(client) }
|
|
150
|
+
Tep::Scheduler.spawn_fiber(conn)
|
|
151
|
+
0
|
|
152
|
+
end
|
|
153
|
+
|
|
142
154
|
# Non-blocking server-side TLS handshake on an accepted fd.
|
|
143
155
|
# Returns 1 on success (SSL* registered -- reads/writes are now
|
|
144
156
|
# transparent), 0 on failure. Drives SSL_do_handshake, parking on
|
data/lib/tep/version.rb
CHANGED
|
@@ -96,6 +96,30 @@ class TestServerScheduled < TepTest
|
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
def test_burst_of_new_connections_each_get_their_own_fiber
|
|
100
|
+
# Connections that arrive together are accepted on consecutive
|
|
101
|
+
# scheduler passes, each before the previous one's fiber has run.
|
|
102
|
+
# The fiber must own the fd it was spawned for: when it read the
|
|
103
|
+
# accept loop's variable instead, two fibers served the newest
|
|
104
|
+
# connection and the earlier one was never answered.
|
|
105
|
+
#
|
|
106
|
+
# The pause lets the harness's port probe (itself a connection)
|
|
107
|
+
# be accepted and finished first; arriving with the burst it takes
|
|
108
|
+
# the lost slot and every real request is still answered.
|
|
109
|
+
sleep 0.3
|
|
110
|
+
socks = Array.new(16) { TCPSocket.new("127.0.0.1", @port) }
|
|
111
|
+
sleep 0.3
|
|
112
|
+
socks.each_with_index do |s, i|
|
|
113
|
+
s.write("GET /echo/c#{i} HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n")
|
|
114
|
+
end
|
|
115
|
+
got = socks.map do |s|
|
|
116
|
+
s.wait_readable(5) ? s.read.to_s.split("\r\n\r\n", 2)[1] : nil
|
|
117
|
+
end
|
|
118
|
+
assert_equal (0...16).map { |i| "c#{i}" }, got
|
|
119
|
+
ensure
|
|
120
|
+
socks.each(&:close) if socks
|
|
121
|
+
end
|
|
122
|
+
|
|
99
123
|
def test_connection_churn_does_not_grow_scheduler_slots
|
|
100
124
|
# Overlapping connections: open the next one before closing the
|
|
101
125
|
# previous, so a live connection fiber always sits at the tail of
|