Skip to content
Browse files

Merge branch 'master' of github.com:edicl/hunchentoot

  • Loading branch information...
2 parents 3a1a1f0 + ba3cdf3 commit 09bdac378dd36d903789dc436d32303ed161214d @hanshuebner hanshuebner committed Sep 2, 2012
Showing with 40 additions and 30 deletions.
  1. +1 −11 acceptor.lisp
  2. +21 −19 taskmaster.lisp
  3. +18 −0 util.lisp
View
12 acceptor.lisp
@@ -316,17 +316,7 @@ they're using secure connections - see the SSL-ACCEPTOR class."))
(defmethod process-connection :around ((*acceptor* acceptor) (socket t))
;; this around method is used for error handling
;; note that this method also binds *ACCEPTOR*
- (handler-bind ((error
- ;; abort if there's an error which isn't caught inside
- (lambda (cond)
- (log-message* *lisp-errors-log-level*
- "Error while processing connection: ~A" cond)
- (return-from process-connection)))
- (warning
- ;; log all warnings which aren't caught inside
- (lambda (cond)
- (log-message* *lisp-warnings-log-level*
- "Warning while processing connection: ~A" cond))))
+ (with-conditions-caught-and-logged ()
(with-mapped-conditions ()
(call-next-method))))
View
40 taskmaster.lisp
@@ -359,25 +359,27 @@ is set up via PROCESS-REQUEST."
(*acceptor* acceptor)
(*hunchentoot-stream* (make-socket-stream socket acceptor)))
(unwind-protect
- (let* ((*hunchentoot-stream* (initialize-connection-stream acceptor *hunchentoot-stream*))
- (*reply* (make-instance (acceptor-reply-class acceptor)))
- (*request*
- (multiple-value-bind (remote-addr remote-port)
- (get-peer-address-and-port socket)
- (make-instance (acceptor-request-class acceptor)
- :acceptor acceptor
- :remote-addr remote-addr
- :remote-port remote-port
- :headers-in nil
- :content-stream nil
- :method nil
- :uri nil
- :server-protocol nil))))
- (with-character-stream-semantics
- (send-response acceptor
- (flex:make-flexi-stream *hunchentoot-stream* :external-format :iso-8859-1)
- +http-service-unavailable+
- :content (acceptor-status-message acceptor +http-service-unavailable+))))
+ (with-conditions-caught-and-logged ()
+ (with-mapped-conditions ()
+ (let* ((*hunchentoot-stream* (initialize-connection-stream acceptor *hunchentoot-stream*))
+ (*reply* (make-instance (acceptor-reply-class acceptor)))
+ (*request*
+ (multiple-value-bind (remote-addr remote-port)
+ (get-peer-address-and-port socket)
+ (make-instance (acceptor-request-class acceptor)
+ :acceptor acceptor
+ :remote-addr remote-addr
+ :remote-port remote-port
+ :headers-in nil
+ :content-stream nil
+ :method nil
+ :uri nil
+ :server-protocol nil))))
+ (with-character-stream-semantics
+ (send-response acceptor
+ (flex:make-flexi-stream *hunchentoot-stream* :external-format :iso-8859-1)
+ +http-service-unavailable+
+ :content (acceptor-status-message acceptor +http-service-unavailable+))))))
(decrement-taskmaster-accept-count taskmaster)
(when *hunchentoot-stream*
(ignore-errors*
View
18 util.lisp
@@ -337,3 +337,21 @@ not a chunked stream."
#-:lispworks
`(usocket:with-mapped-conditions ()
,@body))
+
+(defmacro with-conditions-caught-and-logged (() &body body)
+ "Run BODY with conditions caught and logged by the *ACCEPTOR*. Errors are
+stopped right away so no other part of the software is impacted by them."
+ `(block nil
+ (handler-bind
+ ((error
+ ;; abort if there's an error which isn't caught inside
+ (lambda (cond)
+ (log-message* *lisp-errors-log-level*
+ "Error while processing connection: ~A" cond)
+ (return)))
+ (warning
+ ;; log all warnings which aren't caught inside
+ (lambda (cond)
+ (log-message* *lisp-warnings-log-level*
+ "Warning while processing connection: ~A" cond))))
+ ,@body)))

0 comments on commit 09bdac3

Please sign in to comment.
Something went wrong with that request. Please try again.