Skip to content

Commit

Permalink
Deallocate used prepared statements in a main process, not in GC.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Dec 14, 2016
1 parent ec43fb5 commit 20658c6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/dbd/postgres.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
:initform nil)))

(defmethod prepare ((conn <dbd-postgres-connection>) (sql string) &key)
;; Deallocate used prepared statements here,
;; because GC finalizer may run during processing another query and fail.
(loop for prepared = (pop (slot-value conn '%deallocation-queue))
while prepared
do (unprepare-query (connection-handle conn) prepared))
(let ((name (symbol-name (gensym "PREPARED-STATEMENT"))))
(setf sql
(with-output-to-string (s)
Expand All @@ -65,14 +70,7 @@
(finalize query
(lambda ()
(when (database-open-p conn-handle)
(handler-case
(progn
(unprepare-query conn-handle name)
(loop for name = (pop (slot-value conn '%deallocation-queue))
while name
do (unprepare-query conn-handle name)))
(error ()
(push name (slot-value conn '%deallocation-queue))))))))
(push name (slot-value conn '%deallocation-queue))))))
(syntax-error-or-access-violation (e)
(error '<dbi-programming-error>
:message (database-error-message e)
Expand Down

0 comments on commit 20658c6

Please sign in to comment.