@@ -179,6 +179,8 @@ func DefaultMultiClientSettings() *MultiClientSettings {
179179 DefaultReconnectScale : 1.0 ,
180180 DefaultUlimit : 0 ,
181181
182+ TcpCollapsePrevention : true ,
183+
182184 IngressSecurityPolicyGenerator : DefaultIngressSecurityPolicyWithStats ,
183185 EgressSecurityPolicyGenerator : DefaultEgressSecurityPolicyWithStats ,
184186
@@ -262,6 +264,8 @@ type MultiClientSettings struct {
262264 // used when ulimit is not set in a custom performance profile
263265 DefaultUlimit int
264266
267+ TcpCollapsePrevention bool
268+
265269 IngressSecurityPolicyGenerator func (* SecurityPolicyStatsCollector ) SecurityPolicy
266270 EgressSecurityPolicyGenerator func (* SecurityPolicyStatsCollector ) SecurityPolicy
267271
@@ -923,33 +927,39 @@ func (self *RemoteUserNatMultiClient) SendPacket(
923927 }
924928}
925929
926- func (self * RemoteUserNatMultiClient ) canSendPacket (ipPath * IpPath , update * multiClientChannelUpdate ) bool {
930+ func (self * RemoteUserNatMultiClient ) canSendPacket (ipPath * IpPath , update * multiClientChannelUpdate ) ( allow bool ) {
927931 switch ipPath .Protocol {
928932 case IpProtocolTcp :
929- // limit sender tcp collapse
930- // as soon as a packet is sent to a client, either the client will eith reliabily transfer the packet,
931- // or the client will be dropped
932- // retransmits don't need to be sent as soon as the packet is committed to a client
933-
934- if ipPath .Syn || ipPath .Rst || ipPath .Ack {
935- return true
936- }
937-
938- self .stateLock .Lock ()
939- defer self .stateLock .Unlock ()
933+ if self . settings . TcpCollapsePrevention {
934+ // limit sender tcp collapse
935+ // as soon as a packet is sent to a client, either the client will eith reliabily transfer the packet,
936+ // or the client will be dropped
937+ // retransmits don't need to be sent as soon as the packet is committed to a client
938+ if ipPath .Syn || ipPath .Rst || ipPath .Ack {
939+ allow = true
940+ } else {
941+ func () {
942+ self .stateLock .Lock ()
943+ defer self .stateLock .Unlock ()
940944
941- if update .normalPacketCount == 0 {
942- return true
943- }
945+ if update .normalPacketCount == 0 {
946+ allow = true
947+ return
948+ }
944949
945- if update .sequenceNumber < ipPath .SequenceNumber {
946- return true
950+ if update .sequenceNumber < ipPath .SequenceNumber {
951+ allow = true
952+ return
953+ }
954+ }()
955+ }
956+ } else {
957+ allow = true
947958 }
948-
949- return false
950959 default :
951- return true
960+ allow = true
952961 }
962+ return
953963}
954964
955965func (self * RemoteUserNatMultiClient ) sendPacket (
@@ -986,9 +996,7 @@ func (self *RemoteUserNatMultiClient) sendPacket(
986996 update .sequenceNumber = ipPath .SequenceNumber
987997 }
988998 }()
989- return
990- }
991- if err != nil {
999+ } else if err != nil {
9921000 // reset the path
9931001
9941002 glog .Infof ("[multi]reset error = %s\n " , err )
@@ -1020,6 +1028,8 @@ func (self *RemoteUserNatMultiClient) sendPacket(
10201028 }
10211029 }
10221030 }
1031+ // else the packet was dropped due to backpressure
1032+ // keep sending to the client until there is an error
10231033 return
10241034 }
10251035
0 commit comments