mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
The send-buffer socket option callback stores AutoTuneSndBufDisabled without taking the send queue mutex. CloneState must load it atomically even while holding that mutex. Use atomic access for the copied flag and annotate its atomic-use contract and the source-lock contract. Keep the caller's exclusive ownership of the destination explicit. Exercise the actual option callback and locked snapshot helper in two goroutines. Check that the setter ran and the snapshot copied either legal concurrent value; the old non-atomic read fails under the race detector. The existing end-to-end probe test remains unchanged. Co-authored-by: Hanzo Dev <[email protected]>
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
// Copyright 2026 The gVisor Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package tcp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gvisor.dev/gvisor/pkg/sync"
|
|
)
|
|
|
|
func TestSendBufferStateSnapshot(t *testing.T) {
|
|
var ep Endpoint
|
|
var snapshot TCPSndBufState
|
|
// Neither the initial nor updated endpoint state contains this value.
|
|
snapshot.AutoTuneSndBufDisabled.Store(2)
|
|
|
|
// The socket option callback does not take sndQueueMu. Join only after
|
|
// both accesses so that the wait group cannot serialize them.
|
|
var wg sync.WaitGroup
|
|
wg.Go(func() {
|
|
_ = ep.OnSetSendBufferSize(4096)
|
|
})
|
|
wg.Go(func() {
|
|
ep.sndQueueInfo.sndQueueMu.Lock()
|
|
ep.sndQueueInfo.CloneState(&snapshot)
|
|
ep.sndQueueInfo.sndQueueMu.Unlock()
|
|
})
|
|
wg.Wait()
|
|
|
|
ep.sndQueueInfo.sndQueueMu.Lock()
|
|
sourceDisabled := ep.sndQueueInfo.AutoTuneSndBufDisabled.Load()
|
|
ep.sndQueueInfo.sndQueueMu.Unlock()
|
|
if sourceDisabled != 1 {
|
|
t.Errorf("source AutoTuneSndBufDisabled = %d, want 1", sourceDisabled)
|
|
}
|
|
if got := snapshot.AutoTuneSndBufDisabled.Load(); got > 1 {
|
|
t.Errorf("snapshot AutoTuneSndBufDisabled = %d, want 0 or 1", got)
|
|
}
|
|
}
|