Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion vlib/net/http/server_tls_idle.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,25 @@ fn (mut t TlsIdleConnTracker) unmark_idle(handle int) {

fn (mut t TlsIdleConnTracker) close_idle() {
t.mu.lock()
defer {
t.mu.unlock()
}
Comment thread
JalonSolov marked this conversation as resolved.
t.closing = true
handles := t.handles.clone()
t.handles.clear()
t.mu.unlock()
// Shut down handles under the lock: a worker racing through
// unmark_idle → conn.shutdown() → net.close(fd) could cause the OS
// to reuse the fd before we call net.shutdown here, hitting an
// unrelated socket. Holding the lock keeps unmark_idle serialized
// with this loop, closing the window.
// On Windows, net.shutdown(SD_BOTH) alone does not unblock a blocking
// select() in another thread — only closesocket() does. We call
// net.close here for that reason. The worker's deferred conn.shutdown()
// will call closesocket again; that second call returns WSAENOTSOCK and
// is swallowed by or {}. The double-close is safe: listen_and_serve_tls
// calls ch.close() before close_idle(), so the accept loop has already
// stopped; no new connection can claim the recycled handle before the
// worker's conn.shutdown() runs.
for handle in handles {
net.shutdown(handle)
$if windows {
Expand Down
3 changes: 0 additions & 3 deletions vlib/net/http/server_tls_notd_use_openssl.v
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ fn (mut s Server) listen_and_serve_tls() {
}
continue
}
if s.read_timeout > 0 {
conn.set_read_timeout(s.read_timeout)
}
ch <- conn
}
ch.close()
Expand Down
Loading