               current-state
               (assoc current-state
                 :ch         ch-or-err
-                :next-up-fn write-pending)))
+                :next-dn-fn write-pending)))
           (fn [current-state]
             (if (.aborted? current-state)
               ;; Return to the connection pool

         (when-not (.aborted? current-state)
           (cond-let
            [msg (netty/message-event evt)]
            ((.next-dn-fn current-state) state msg current-state)

            ;; The channel interest has changed to writable
            ;; or not writable
            [[ch-state val] (netty/channel-state-event evt)]
            (cond
             (and (nil? val) (= ch-state ChannelState/CONNECTED)
                  (not= request-complete (.next-up-fn current-state)))
             (handle-err state (Exception. "Connection reset by peer") current-state)

             (= ch-state ChannelState/INTEREST_OPS)
             (handle-ch-interest-change state current-state writable?))

            [_ (netty/write-completion-event evt)]
            (when (and (= write-pending (.next-up-fn current-state))
                       (.. evt getFuture isSuccess))
              (initial-write-succeeded state current-state))

            [err (netty/exception-event evt)]
            (do (.printStackTrace err)))))))))

(defn- mk-upstream-fn
  [state]
  (fn [evt val]
    (let [current-state @state]

          (.isChunked msg)
          (assoc current-state
            :keepalive? keepalive?
            :next-up-fn stream-or-finalize-response)

          ;; If the exchange is waiting for the response to complete then
          ;; finish everything up
          (= response-pending (.next-dn-fn current-state))
          (assoc current-state
            :keepalive? keepalive?
            :next-dn-fn request-complete
            :next-up-fn nil)

          ;; Otherwise, just mark the request as done
          :else
          (assoc current-state
            :keepalive? keepalive?
            :next-up-fn nil))))
     finalize-request)
    (upstream-fn downstream-fn :response (netty-resp->resp msg))))

(defn- initial-write-succeeded
  [state current-state]
