mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-25 04:37:42 +00:00
ipn/{ipnlocal,ipnserver}: remove redundant (*LocalBackend).ResetForClientDisconnect
In this commit, we add a failing test to verify that ipn/ipnserver.Server correctly sets and unsets the current user when two different users connect sequentially (A connects, A disconnects, B connects, B disconnects). We then fix the test by updating (*ipn/ipnserver.Server).addActiveHTTPRequest to avoid calling (*LocalBackend).ResetForClientDisconnect again after a new user has connected and been set as the current user with (*LocalBackend).SetCurrentUser(). Since ipn/ipnserver.Server does not allow simultaneous connections from different Windows users and relies on the LocalBackend's current user, and since we already reset the LocalBackend's state by calling ResetForClientDisconnect when the last active request completes (indicating the server is idle and can accept connections from any Windows user), it is unnecessary to track the last connected user on the ipnserver.Server side or call ResetForClientDisconnect again when the user changes. Additionally, the second call to ResetForClientDisconnect occurs after the new user has been set as the current user, resetting the correct state for the new user instead of the old state of the now-disconnected user, causing issues. Updates tailscale/corp#25804 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -158,6 +158,35 @@ func TestIPNAlreadyInUseOnWindows(t *testing.T) {
|
||||
server.checkCurrentUser(clientA.User)
|
||||
}
|
||||
|
||||
func TestSequentialOSUserSwitchingOnWindows(t *testing.T) {
|
||||
enableLogging := false
|
||||
setGOOSForTest(t, "windows")
|
||||
|
||||
ctx := context.Background()
|
||||
server := startDefaultTestIPNServer(t, ctx, enableLogging)
|
||||
|
||||
connectDisconnectAsUser := func(name string) {
|
||||
// User connects and starts watching the IPN bus.
|
||||
client := server.getClientAs(name)
|
||||
watcher, cancelWatcher := client.WatchIPNBus(ctx, 0)
|
||||
defer cancelWatcher()
|
||||
go pumpIPNBus(watcher)
|
||||
|
||||
// It should be the current user from the LocalBackend's perspective...
|
||||
server.checkCurrentUser(client.User)
|
||||
// until it disconnects.
|
||||
cancelWatcher()
|
||||
server.blockWhileInUse(ctx)
|
||||
// Now, the current user should be unset.
|
||||
server.checkCurrentUser(nil)
|
||||
}
|
||||
|
||||
// UserA logs in, uses Tailscale for a bit, then logs out.
|
||||
connectDisconnectAsUser("UserA")
|
||||
// Same for UserB.
|
||||
connectDisconnectAsUser("UserB")
|
||||
}
|
||||
|
||||
func setGOOSForTest(tb testing.TB, goos string) {
|
||||
tb.Helper()
|
||||
envknob.Setenv("TS_DEBUG_FAKE_GOOS", goos)
|
||||
|
Reference in New Issue
Block a user