@@ -222,6 +222,7 @@ impl Connection {
222222
223223 self . command_executing = true ;
224224
225+ let max_message_size = self . max_message_size_bytes ( ) ;
225226 #[ cfg( any(
226227 feature = "zstd-compression" ,
227228 feature = "zlib-compression" ,
@@ -230,30 +231,30 @@ impl Connection {
230231 let write_result = match self . compressor {
231232 Some ( ref compressor) if message. should_compress => {
232233 message
233- . write_op_compressed_to ( & mut self . stream , compressor)
234+ . write_op_compressed_to ( & mut self . stream , compressor, max_message_size)
235+ . await
236+ }
237+ _ => {
238+ message
239+ . write_op_msg_to ( & mut self . stream , max_message_size)
234240 . await
235241 }
236- _ => message. write_op_msg_to ( & mut self . stream ) . await ,
237242 } ;
238243 #[ cfg( all(
239244 not( feature = "zstd-compression" ) ,
240245 not( feature = "zlib-compression" ) ,
241246 not( feature = "snappy-compression" )
242247 ) ) ]
243- let write_result = message. write_op_msg_to ( & mut self . stream ) . await ;
248+ let write_result = message
249+ . write_op_msg_to ( & mut self . stream , max_message_size)
250+ . await ;
244251
245252 if let Err ( ref err) = write_result {
246253 self . error = Some ( err. clone ( ) ) ;
247254 }
248255 write_result?;
249256
250- let response_message_result = Message :: read_from (
251- & mut self . stream ,
252- self . stream_description
253- . as_ref ( )
254- . map ( |d| d. max_message_size_bytes ) ,
255- )
256- . await ;
257+ let response_message_result = Message :: read_from ( & mut self . stream , max_message_size) . await ;
257258 self . command_executing = false ;
258259 if let Err ( ref err) = response_message_result {
259260 self . error = Some ( err. clone ( ) ) ;
@@ -306,6 +307,12 @@ impl Connection {
306307 pub ( crate ) fn is_streaming ( & self ) -> bool {
307308 self . more_to_come
308309 }
310+
311+ fn max_message_size_bytes ( & self ) -> Option < i32 > {
312+ self . stream_description
313+ . as_ref ( )
314+ . map ( |d| d. max_message_size_bytes )
315+ }
309316}
310317
311318/// A handle to a pinned connection - the connection itself can be retrieved or returned to the
0 commit comments