@@ -222,6 +222,7 @@ impl Connection {
222
222
223
223
self . command_executing = true ;
224
224
225
+ let max_message_size = self . max_message_size_bytes ( ) ;
225
226
#[ cfg( any(
226
227
feature = "zstd-compression" ,
227
228
feature = "zlib-compression" ,
@@ -230,30 +231,30 @@ impl Connection {
230
231
let write_result = match self . compressor {
231
232
Some ( ref compressor) if message. should_compress => {
232
233
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)
234
240
. await
235
241
}
236
- _ => message. write_op_msg_to ( & mut self . stream ) . await ,
237
242
} ;
238
243
#[ cfg( all(
239
244
not( feature = "zstd-compression" ) ,
240
245
not( feature = "zlib-compression" ) ,
241
246
not( feature = "snappy-compression" )
242
247
) ) ]
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 ;
244
251
245
252
if let Err ( ref err) = write_result {
246
253
self . error = Some ( err. clone ( ) ) ;
247
254
}
248
255
write_result?;
249
256
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 ;
257
258
self . command_executing = false ;
258
259
if let Err ( ref err) = response_message_result {
259
260
self . error = Some ( err. clone ( ) ) ;
@@ -306,6 +307,12 @@ impl Connection {
306
307
pub ( crate ) fn is_streaming ( & self ) -> bool {
307
308
self . more_to_come
308
309
}
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
+ }
309
316
}
310
317
311
318
/// A handle to a pinned connection - the connection itself can be retrieved or returned to the
0 commit comments