@@ -826,7 +826,8 @@ namespace net_utils
826826 return false ;
827827
828828 // Wait for the write queue to fall below the max. If it doesn't after a
829- // randomized delay, drop the connection.
829+ // randomized delay, drop the connection. P2P senders fail fast instead of
830+ // parking an io_context worker thread here.
830831 auto wait_consume = [this ] {
831832 auto random_delay = []{
832833 using engine = std::mt19937;
@@ -850,6 +851,12 @@ namespace net_utils
850851 if (m_state.data .write .queue .size () <= ABSTRACT_SERVER_SEND_QUE_MAX_COUNT &&
851852 m_state.data .write .total_bytes <= static_cast <shared_state&>(connection_basic::get_state ()).response_soft_limit )
852853 return true ;
854+
855+ if (m_connection_type == e_connection_type_P2P) {
856+ MWARNING (" Connection " << m_conn_context.m_connection_id << " tripped write limit, terminating" );
857+ terminate_async ();
858+ return false ;
859+ }
853860 m_state.data .write .wait_consume = true ;
854861 bool success = m_state.condition .wait_for (
855862 m_state.lock ,
@@ -888,7 +895,11 @@ namespace net_utils
888895 };
889896 if (!wait_sender ())
890897 return false ;
891- constexpr size_t CHUNK_SIZE = 32 * 1024 ;
898+ /* CHUNK_SIZE indirectly caps outgoing to 128 * 1024 * 1000
899+ (ABSTRACT_SERVER_SEND_QUE_MAX_COUNT). The "soft" limit total is currently
900+ 100 MiB (ABSTRACT_SERVER_SEND_QUE_MAX_BYTES_DEFAULT). These values will
901+ need to be re-visited alongside block limit increases. */
902+ constexpr size_t CHUNK_SIZE = 128 * 1024 ;
892903 if (m_connection_type == e_connection_type_RPC ||
893904 message.size () <= 2 * CHUNK_SIZE
894905 ) {
@@ -900,13 +911,19 @@ namespace net_utils
900911 start_write ();
901912 }
902913 else {
914+ std::size_t soft_limit = 0 ;
915+ const epee::misc_utils::auto_scope_leave_caller scope_exit_handler =
916+ epee::misc_utils::create_scope_leave_handler ([&soft_limit, this ] {
917+ m_state.data .write .total_bytes += soft_limit;
918+ });
919+
903920 while (!message.empty ()) {
904921 if (!wait_consume ())
905922 return false ;
906923 m_state.data .write .queue .emplace_front (
907924 message.take_slice (CHUNK_SIZE )
908925 );
909- m_state. data . write . total_bytes += m_state.data .write .queue .front ().size ();
926+ soft_limit += m_state.data .write .queue .front ().size ();
910927 start_write ();
911928 }
912929 }
0 commit comments