@@ -64,20 +64,29 @@ impl ProxyServer {
6464 }
6565
6666 pub ( crate ) fn set_tls_config ( & self , cert_pem : String , key_pem : String ) -> Result < ( ) , ApiError > {
67- let mut lock = self . config . lock ( ) . unwrap ( ) ;
67+ let mut lock = self
68+ . config
69+ . lock ( )
70+ . expect ( "Failed to acquire lock on config mutex when updating TLS configuration" ) ;
6871 let config = lock. get_or_insert_with ( Configuration :: default) ;
6972 config. grpc_cert_pem = cert_pem;
7073 config. grpc_key_pem = key_pem;
7174 Ok ( ( ) )
7275 }
7376
7477 pub ( crate ) fn configure ( & self , config : Configuration ) {
75- let mut lock = self . config . lock ( ) . unwrap ( ) ;
78+ let mut lock = self
79+ . config
80+ . lock ( )
81+ . expect ( "Failed to acquire lock on config mutex when applying proxy configuration" ) ;
7682 * lock = Some ( config) ;
7783 }
7884
7985 pub ( crate ) fn get_configuration ( & self ) -> Option < Configuration > {
80- let lock = self . config . lock ( ) . unwrap ( ) ;
86+ let lock = self
87+ . config
88+ . lock ( )
89+ . expect ( "Failed to acquire lock on config mutex when retrieving proxy configuration" ) ;
8190 lock. clone ( )
8291 }
8392
@@ -130,7 +139,13 @@ impl ProxyServer {
130139 payload : core_request:: Payload ,
131140 device_info : DeviceInfo ,
132141 ) -> Result < oneshot:: Receiver < core_response:: Payload > , ApiError > {
133- if let Some ( client_tx) = self . clients . lock ( ) . unwrap ( ) . values ( ) . next ( ) {
142+ if let Some ( client_tx) = self
143+ . clients
144+ . lock ( )
145+ . expect ( "Failed to acquire lock on clients hashmap when sending message to core" )
146+ . values ( )
147+ . next ( )
148+ {
134149 let id = self . current_id . fetch_add ( 1 , Ordering :: Relaxed ) ;
135150 let res = CoreRequest {
136151 id,
@@ -142,7 +157,10 @@ impl ProxyServer {
142157 return Err ( ApiError :: Unexpected ( "Failed to send CoreRequest" . into ( ) ) ) ;
143158 }
144159 let ( tx, rx) = oneshot:: channel ( ) ;
145- self . results . lock ( ) . unwrap ( ) . insert ( id, tx) ;
160+ self . results
161+ . lock ( )
162+ . expect ( "Failed to acquire lock on results hashmap when sending CoreRequest" )
163+ . insert ( id, tx) ;
146164 self . connected . store ( true , Ordering :: Relaxed ) ;
147165 Ok ( rx)
148166 } else {
@@ -155,7 +173,10 @@ impl ProxyServer {
155173 }
156174
157175 pub ( crate ) fn setup_completed ( & self ) -> bool {
158- let lock = self . config . lock ( ) . unwrap ( ) ;
176+ let lock = self
177+ . config
178+ . lock ( )
179+ . expect ( "Failed to acquire lock on config mutex when checking setup status" ) ;
159180 lock. is_some ( )
160181 }
161182}
@@ -197,7 +218,9 @@ impl proxy_server::Proxy for ProxyServer {
197218 } ;
198219 let maybe_info = ComponentInfo :: from_metadata ( request. metadata ( ) ) ;
199220 let ( version, info) = get_tracing_variables ( & maybe_info) ;
200- * self . core_version . lock ( ) . unwrap ( ) = Some ( version. clone ( ) ) ;
221+ * self . core_version . lock ( ) . expect (
222+ "Failed to acquire lock on core_version mutex when storing version information" ,
223+ ) = Some ( version. clone ( ) ) ;
201224
202225 let span = tracing:: info_span!( "core_bidi_stream" , component = %DefguardComponent :: Core ,
203226 version = version. to_string( ) , info) ;
@@ -206,7 +229,12 @@ impl proxy_server::Proxy for ProxyServer {
206229 info ! ( "Defguard Core gRPC client connected from: {address}" ) ;
207230
208231 let ( tx, rx) = mpsc:: unbounded_channel ( ) ;
209- self . clients . lock ( ) . unwrap ( ) . insert ( address, tx) ;
232+ self . clients
233+ . lock ( )
234+ . expect (
235+ "Failed to acquire lock on clients hashmap when registering new core connection" ,
236+ )
237+ . insert ( address, tx) ;
210238 self . connected . store ( true , Ordering :: Relaxed ) ;
211239
212240 let clients = Arc :: clone ( & self . clients ) ;
@@ -221,7 +249,7 @@ impl proxy_server::Proxy for ProxyServer {
221249 debug ! ( "Received message from Defguard Core ID={}" , response. id) ;
222250 connected. store ( true , Ordering :: Relaxed ) ;
223251 if let Some ( payload) = response. payload {
224- let maybe_rx = results. lock ( ) . unwrap ( ) . remove ( & response. id ) ;
252+ let maybe_rx = results. lock ( ) . expect ( "Failed to acquire lock on results hashmap when processing response" ) . remove ( & response. id ) ;
225253 if let Some ( rx) = maybe_rx {
226254 if let Err ( err) = rx. send ( payload) {
227255 error ! ( "Failed to send message to rx {:?}" , err. type_id( ) ) ;
@@ -243,7 +271,7 @@ impl proxy_server::Proxy for ProxyServer {
243271 }
244272 info ! ( "Defguard core client disconnected: {address}" ) ;
245273 connected. store ( false , Ordering :: Relaxed ) ;
246- clients. lock ( ) . unwrap ( ) . remove ( & address) ;
274+ clients. lock ( ) . expect ( "Failed to acquire lock on clients hashmap when removing disconnected client" ) . remove ( & address) ;
247275 }
248276 . instrument ( tracing:: Span :: current ( ) ) ,
249277 ) ;
0 commit comments