Skip to content

Commit

Permalink
Fix handler threading
Browse files Browse the repository at this point in the history
This patch fixes a bug where the response logic was inadvertently running within core.async thread
context.  I believe this was a side-effect of how promesa schedules p/then in conjunction with the
go-routine in transmit-trailers...the finally clause was piggy-backing on the core.async thread
when we intended it to run from the thread-pool.

This patch ensures that we return to the thread-pool context before executing the finally clause.

The fix has been confirmed via yourkit profiling.

Signed-off-by: Greg Haskins <[email protected]>
  • Loading branch information
ghaskins committed Jun 23, 2023
1 parent d09eb0d commit abe69c2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions modules/grpc-server/src/protojure/pedestal/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@

;; Start asynchronous output
(let [output-ch (open-output-channel exchange)]
@(-> (p/all [input-status
(transmit-trailers exchange trailers)
(transmit-body output-ch body)])
(p/finally (fn [_ _]
(close-output-channel exchange output-ch)
(unsubscribe-close connections exchange)
(.endExchange exchange))))))
(try
@(p/all [input-status
(transmit-trailers exchange trailers)
(transmit-body output-ch body)])
(finally
(close-output-channel exchange output-ch)
(unsubscribe-close connections exchange)
(.endExchange exchange)))))

(defn provider
"Generates our undertow provider, which defines the callback point between
Expand Down

0 comments on commit abe69c2

Please sign in to comment.