Fixing PR12443

There is a big comment in thread.rkt that explains the problem and the
"fix". I think something better could and should be done, but I don't
know what it is.

original commit: 022ce2d8d7de60d63d21eb67119466283d9e8be3
This commit is contained in:
Jay McCarthy 2012-01-03 14:11:00 -07:00
parent 2410b71326
commit fbea030c27

View File

@ -67,19 +67,39 @@
(let ([paramz (current-parameterization)])
;; Loop to handle connections:
(let loop ()
(with-handlers ([exn:fail:network? handle-exn])
;; Introducing this thread causes PR12443 to no longer fail.
;; The Web Server will definitely kill the custodian
;; associated with the resources of the connection. I
;; think what is going on is that the loop here is
;; attached to one of these custodians (eventually)
;; and then the listening loop thread gets killed
;; too. This patch basically just disconnects the loop
;; from the new custodian. The error reported in the
;; PR still shows up, but it has no effect on the
;; response time/etc, whereas before it would stop
;; listening and 'ab' would fail.
(thread-wait
(thread
(λ ()
(with-handlers
([exn:fail:network? handle-exn])
;; Make a custodian for the next session:
(let ([c (make-custodian)])
(parameterize ([current-custodian c])
(parameterize
([current-custodian c])
;; disable breaks during session set-up...
(parameterize-break #f
(parameterize-break
#f
;; ... but enable breaks while blocked on an accept:
(let-values ([(r w) ((if can-break?
tcp-accept/enable-break
tcp-accept)
l)])
;; Handler thread:
(let ([t (thread (lambda ()
(let ([t
(thread
(lambda ()
;; First, install the parameterization
;; used for all connections:
(call-with-parameterization
@ -95,13 +115,14 @@
;; Call the handler
(handler r w)))))])
;; Clean-up and timeout thread:
(thread (lambda ()
(thread
(lambda ()
(sync/timeout connection-timeout t)
(when (thread-running? t)
;; Only happens if connection-timeout is not #f
(break-thread t))
(sync/timeout connection-timeout t)
(custodian-shutdown-all c)))))))))
(custodian-shutdown-all c))))))))))))
(loop))))
(lambda () (tcp-close l)))))