   "Send a message across the websocket session"
   [client :- Client message :- message/Message]
   (let [{:keys [identity websocket-connection]} client]
-    (if-not (realized? @websocket-connection)
+    (if-not (and (realized? @websocket-connection) (not (= true @@websocket-connection)))
       (throw+ {:type ::not-connected})
       (ws/send-msg @@websocket-connection
                    (message/encode (assoc message :sender identity))))

  "Close the connection"
  [client :- Client]
  (let [{:keys [should-stop websocket-client websocket-connection]} client]
    (deliver should-stop true)
    (when (contains? #{:opening :open} (state client))
      (log/debug "Closing")
      (reset! (:state client) :closing)
      (.stop websocket-client))
    (when (realized? @websocket-connection)
      (ws/close @@websocket-connection))
    true))

        client (merge params {:identity (make-identity cert type)
                              :state (atom :connecting :validator ws-state?)
                              :websocket-client (make-websocket-client params)
                              :websocket-connection (atom (future true))
                              :handlers handlers
                              :should-stop (promise)})
        {:keys [websocket-connection]} client]
