208a969
Branches > main > 208a969 > files
Log unexpected exceptions in connection.clj
Commit: 208a96930ced34f7c6f497b68a1a09fb0db641ae
Parent: bce7b6a
1 changed file:
src/net/bowmap/server/network/connection.clj view file
@@ -2,8 +2,11 @@ "A connection to the Minecraft server." (:require [clojure.spec.alpha :as s]+ [clojure.stacktrace :refer [print-stack-trace]]+ [clojure.tools.logging :as log] [net.bowmap.server.network.streams :as streams]) (:import+ [java.io IOException] [java.net Socket])) (defprotocol Connection@@ -15,6 +18,12 @@ (s/def ::connection #(satisfies? Connection %)) +(defn- log-unexpected-exception [ex]+ (when-not (instance? IOException ex)+ (log/warn+ (with-out-str+ (print-stack-trace ex)))))+ (defn connection "Creates a connection from a given java.net.Socket." [socket]@@ -25,11 +34,13 @@ (send-frame! [_ frame] (Thread/startVirtualThread #(try (streams/write-frame!! frame output-stream)- (catch Exception _- (Socket/.close socket))))+ (catch Exception e+ (Socket/.close socket)+ (log-unexpected-exception e)))) nil) (receive-frame!! [_] (try (streams/read-frame!! input-stream)- (catch Exception _+ (catch Exception e (Socket/.close socket)+ (log-unexpected-exception e) nil))))))