Stack backoff rework (#83)

* huge Stack backoff rework

* lneto bump: huge Stack backoff rework
This commit is contained in:
Pat Whittingslow
2026-04-14 21:05:02 -03:00
committed by GitHub
parent 75a812a8d7
commit 16c2c3de36
13 changed files with 153 additions and 85 deletions
@@ -199,7 +199,7 @@ func run() error {
}()
// Create blocking + Berkeley stack
blocking := stack.StackBlocking(5 * time.Millisecond)
blocking := stack.StackBlocking(stackBackoff)
berkeley := blocking.StackGo(xnet.StackGoConfig{
ListenerPoolConfig: xnet.TCPPoolConfig{
PoolSize: uint16(flagPoolSize),
@@ -212,7 +212,7 @@ func run() error {
})
// Perform DHCP to get address.
rstack := stack.StackRetrying(5 * time.Millisecond)
rstack := stack.StackRetrying(stackBackoff)
const dhcpTimeout = 6 * time.Second
const dhcpRetries = 2
results, err := rstack.DoDHCPv4([4]byte{192, 168, 1, 96}, dhcpTimeout, dhcpRetries)
@@ -399,3 +399,10 @@ func mockClient(stack *xnet.StackAsync, port uint16, subnet netip.Prefix) {
fmt.Println("mockclient: received response:\n", string(page))
mockConn.Close()
}
func stackBackoff(consecutiveBackoffs uint) time.Duration {
if consecutiveBackoffs < 10 {
return time.Millisecond
}
return 10 * time.Millisecond
}
+8 -1
View File
@@ -190,7 +190,7 @@ func run() (err error) {
}
}()
rstack := stack.StackRetrying(5 * time.Millisecond)
rstack := stack.StackRetrying(stackBackoff)
const (
dhcpTimeout = 6 * time.Second
@@ -354,3 +354,10 @@ func tryPoll(iface ltesto.Interface, poll time.Duration) (dataMayBeReady bool, _
dataMayBeReady = true
return dataMayBeReady, nil
}
func stackBackoff(consecutiveBackoffs uint) time.Duration {
if consecutiveBackoffs < 10 {
return time.Millisecond
}
return 10 * time.Millisecond
}
+9 -2
View File
@@ -79,7 +79,7 @@ func run(ctx context.Context, stack *xnet.StackAsync) error {
// Other option is to instead use async API which leads to more verbose
// and more stateful code.
go stackLoop(ctx, stack)
rstack := stack.StackRetrying(pollTime)
rstack := stack.StackRetrying(stackBackoff)
results, err := rstack.DoDHCPv4([4]byte{}, protoTimeout, protoRetries)
if err != nil {
return fmt.Errorf("doing DHCP: %w", err)
@@ -93,7 +93,7 @@ func run(ctx context.Context, stack *xnet.StackAsync) error {
return fmt.Errorf("resolving router MAC: %w", err)
}
stack.SetGateway6(gateway)
berkstack := stack.StackBlocking(pollTime).StackGo(xnet.StackGoConfig{
berkstack := stack.StackBlocking(stackBackoff).StackGo(xnet.StackGoConfig{
ListenerPoolConfig: xnet.TCPPoolConfig{
PoolSize: tcpConnPoolSize,
QueueSize: tcpPacketQueueSize,
@@ -171,3 +171,10 @@ func must(err error) {
panic(err)
}
}
func stackBackoff(consecutiveBackoffs uint) time.Duration {
if consecutiveBackoffs < 10 {
return time.Millisecond
}
return 10 * time.Millisecond
}
+8 -1
View File
@@ -212,7 +212,7 @@ func run() (err error) {
}
}()
rstack := stack.StackRetrying(5 * time.Millisecond)
rstack := stack.StackRetrying(stackBackoff)
const (
dhcpTimeout = 6 * time.Second
@@ -382,3 +382,10 @@ func tryPoll(iface ltesto.Interface, poll time.Duration) (dataMayBeReady bool, _
dataMayBeReady = true
return dataMayBeReady, nil
}
func stackBackoff(consecutiveBackoffs uint) time.Duration {
if consecutiveBackoffs < 10 {
return time.Millisecond
}
return 10 * time.Millisecond
}