Skip to content

Commit a34b974

Browse files
committed
multi: test fixes
1 parent 2379b2f commit a34b974

2 files changed

Lines changed: 40 additions & 24 deletions

File tree

ip_remote_multi_client.go

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

955965
func (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

ip_remote_multi_client_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,16 @@ func testingNewMultiClient(ctx context.Context, providerClient *Client, receiveP
125125
},
126126
}
127127

128-
multiClient := NewRemoteUserNatMultiClientWithDefaults(
128+
settings := DefaultMultiClientSettings()
129+
// TODO the tcp packets must use real seq numbers for this to work
130+
settings.TcpCollapsePrevention = false
131+
132+
multiClient := NewRemoteUserNatMultiClient(
129133
ctx,
130134
generator,
131135
receivePacketCallback,
132136
protocol.ProvideMode_Network,
137+
settings,
133138
)
134139

135140
return multiClient, nil
@@ -222,6 +227,7 @@ func TestMultiClientChannelWindowStats(t *testing.T) {
222227
settings := DefaultMultiClientSettings()
223228
settings.StatsWindowBucketDuration = 100 * time.Millisecond
224229
settings.StatsWindowDuration = 1 * time.Second
230+
settings.BlackholeTimeout = 300 * time.Second
225231

226232
// the coalesce logic trims from the last event in a bucket
227233
// if events are uniformly distributed in a bucket, this means there will be an extra bucket

0 commit comments

Comments
 (0)