Skip to content

Commit

Permalink
Review abnormal termination code path.
Browse files Browse the repository at this point in the history
In case of an exceptional condition leading to termination of the pgloader
program we tried to use log-message after the monitor should have been
closed. Also the 0.3s delay to let latests messages out looks like a poor
design.

This patch attempts to remedy both the situation: refrain from using a
closed down monitoring thread, and properly wait until it's done before
returning to the shell.

See #583.
  • Loading branch information
dimitri committed Jun 27, 2017
1 parent 352f4ad commit 2341ef1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/main.lisp
Expand Up @@ -345,13 +345,17 @@

(source-definition-error (c)
(declare (ignore c)) ; handler-bind printed it out
(sleep 0.3) ; wait until monitor stops...
;; wait until monitor stops...
(let ((lp:*kernel* *monitoring-kernel*))
(lp:end-kernel :wait t))
(uiop:quit +os-code-error-bad-source+))

(condition (c)
(declare (ignore c)) ; handler-bind printed it out
(log-message :log "What I am doing here?")
(sleep 0.3) ; wait until monitor stops...
(format *error-output* "~%What I am doing here?~%~%")
;; wait until monitor stops...
(let ((lp:*kernel* *monitoring-kernel*))
(lp:end-kernel :wait t))
(uiop:quit +os-code-error+)))))

;; done.
Expand Down
1 change: 1 addition & 0 deletions src/package.lisp
Expand Up @@ -220,6 +220,7 @@
(defpackage #:pgloader.monitor
(:use #:cl #:pgloader.params #:pgloader.state)
(:export #:with-monitor
#:*monitoring-kernel*
#:*monitoring-queue*
#:log-message
#:new-label
Expand Down
11 changes: 9 additions & 2 deletions src/utils/monitor.lisp
Expand Up @@ -12,6 +12,9 @@
;;;
(in-package :pgloader.monitor)

(defvar *monitoring-kernel* nil
"Internal lparallel kernel to manage the separate monitor thread.")

(defvar *monitoring-queue* nil
"Internal lparallel queue where to send and receive messages from.")

Expand Down Expand Up @@ -130,8 +133,12 @@
(*standard-output* . ,*standard-output*)
(*summary-pathname* . ,*summary-pathname*)
(*sections* . ',*sections*)))
(lparallel:*kernel* (lp:make-kernel 1 :bindings bindings))
(*monitoring-channel* (lp:make-channel)))
(kernel (lp:make-kernel 1 :bindings bindings))
(lparallel:*kernel* kernel))

;; make our kernel and channel visible from the outside
(setf *monitoring-kernel* kernel
*monitoring-channel* (lp:make-channel))

(lp:submit-task *monitoring-channel* #'monitor *monitoring-queue*)
(send-event (make-start :start-logger start-logger))
Expand Down

0 comments on commit 2341ef1

Please sign in to comment.