TUN-8775: Make sure the session Close can only be called once

The previous capture of the sync.OnceValue was re-initialized for each
call to `Close`. This needed to be initialized during the creation of
the session to ensure that the sync.OnceValue reference was held for
the session's lifetime.

Closes TUN-8775
This commit is contained in:
Devin Carr
2024-12-05 14:12:53 -08:00
parent f07d04d129
commit 37010529bc
2 changed files with 19 additions and 9 deletions

View File

@@ -255,11 +255,16 @@ func TestSessionClose_Multiple(t *testing.T) {
if !origin.closed.Load() {
t.Fatal("origin wasn't closed")
}
// Reset the closed status to make sure it isn't closed again
origin.closed.Store(false)
// subsequent closes shouldn't call close again or cause any errors
err = session.Close()
if err != nil {
t.Fatal(err)
}
if origin.closed.Load() {
t.Fatal("origin was incorrectly closed twice")
}
}
func TestSessionServe_IdleTimeout(t *testing.T) {