Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/internal/session/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ func (m *Manager) run() {
if request.result == "changed" && state.status.State == "reconnecting" {
clearTimer(&retryTimer, &retryC)
m.networkChanged(&state, "resync", 0, time.Now())
} else if request.result == "changed" && state.status.State == "error" && state.status.Error == "no_server_answers" {
// the session had ended: one new attempt, as if the person pressed the button, and the status keeps saying why
clearTimer(&healthTimer, &healthC)
clearTimer(&retryTimer, &retryC)
target := state.target
target.Server = state.userServer
if _, err := m.connect(&state, target, false); err == nil {
state.status.Resync, state.status.ResyncUnix = request.result, time.Now().Unix()
m.hub.Publish("status", state.status)
}
}
}
case networkChangedRequest:
Expand Down Expand Up @@ -611,6 +621,7 @@ func (m *Manager) run() {
}
always := m.currentSettings().KillSwitch == "always"
retry := false
byRule := state.status.WhitelistByRule
switch {
case code == "no_subscription":
// nothing to connect to, so nothing to hold the network for: let go of it as a disconnect does
Expand Down Expand Up @@ -669,6 +680,10 @@ func (m *Manager) run() {
m.offerWhitelist(&state)
}
}
if byRule && !retry && code != "no_subscription" {
// the window words the end of the channel for allowlists in its own way: the mark outlives the session
state.status.Purpose = profile.PurposeWhitelist
}
if retry {
if state.status.State != "reconnecting" {
state.status.State = "reconnecting"
Expand Down
42 changes: 42 additions & 0 deletions core/internal/session/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func TestSessionScenarios(t *testing.T) {
{name: "a human connect over a waiting boot connect", run: testBootConnectGivesWayToAHuman},
{name: "no_subscription stops the engine and ends in error", run: testNoSubscriptionStopsTheEngine},
{name: "a resync reports its result and a changed one retries at once", run: testResyncRetriesWhenChanged},
{name: "a changed resync gives an ended first connect one new attempt", run: testResyncRestartsEndedConnect},
{name: "the rule-selected allowlist path keeps its mark when the session ends", run: testWhitelistByRuleKeepsMarkOnError},
{name: "always unavailable hold is not reported as blocked", run: testAlwaysUnavailableHoldIsNotBlocked},
{name: "settings changes apply hold transitions", run: testSettingsChangesApplyHoldTransitions},
{name: "off reconnect does not hold", run: testOffReconnectDoesNotHold},
Expand Down Expand Up @@ -1386,3 +1388,43 @@ func testResyncRetriesWhenChanged(t *testing.T) {
t.Fatalf("Start() calls = %d, resync = %q; want a new attempt at once and no resync once connected", got, status.Resync)
}
}

// A first connect that ended in an error is not retried by itself; other settings from the panel are a reason for one
// new attempt, and one only. The status says why while it runs.
func testResyncRestartsEndedConnect(t *testing.T) {
fake := engine.NewFake(engine.FakeConfig{StepDelay: 20 * time.Millisecond, FailStartCode: "no_server_answers"})
manager, subscription := retryManager(t, fake, "off", time.Hour)
_, _ = manager.Connect(context.Background(), engine.Target{})
waitForStatus(t, subscription.C, func(status Status) bool { return status.State == "error" && status.Error == "no_server_answers" })
manager.Resync("running")
manager.Resync("same")
waitForStatus(t, subscription.C, func(status Status) bool { return status.Resync == "same" })
if got := fake.StartCount(); got != 1 {
t.Fatalf("Start() calls = %d, want no attempt after the same settings", got)
}
manager.Resync("changed")
waitForStatus(t, subscription.C, func(status Status) bool { return status.State == "connecting" && status.Resync == "changed" })
failed := waitForStatus(t, subscription.C, func(status Status) bool { return status.State == "error" })
time.Sleep(50 * time.Millisecond)
if got := fake.StartCount(); got != 2 || failed.Error != "no_server_answers" {
t.Fatalf("Start() calls = %d, error = %q; want exactly one new attempt", got, failed.Error)
}
fake.SetFailStartCode("")
manager.Resync("changed")
connected := waitForStatus(t, subscription.C, func(status Status) bool { return status.State == "connected" })
if got := fake.StartCount(); got != 3 || connected.Resync != "" {
t.Fatalf("Start() calls = %d, resync = %q", got, connected.Resync)
}
}

// Auto moved to the path for allowlists by the rule and that session ended: the status still names the path's purpose
// and the rule, so the window can say that it was the allowlist channel that did not come up.
func testWhitelistByRuleKeepsMarkOnError(t *testing.T) {
_, fake, subscription := whitelistManager(t, true)
waitForStatus(t, subscription.C, func(status Status) bool { return status.State == "reconnecting" && status.WhitelistByRule })
fake.SetFailStartCode("unsupported_os") // a failure no retry answers
ended := waitForStatus(t, subscription.C, func(status Status) bool { return status.State == "blocked" || status.State == "error" })
if ended.Purpose != profile.PurposeWhitelist || !ended.WhitelistByRule {
t.Fatalf("ended session = %#v; want the purpose and the rule kept", ended)
}
}
9 changes: 6 additions & 3 deletions docs/ipc.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ While the server in use (connecting or connected) is one marked `purpose: whitel
ordinary servers do not answer and this subscription has a server for allowlists": it rises when an ordinary server
failed for a reason of the network (a connect that failed outright; two failed retries in `reconnect`; a whole failed
round in `next`) and `whitelist_auto` did not act, and falls when an ordinary server connects, the person picks a
server, or the subscriptions change. The three keys are absent when they do not apply.
server, or the subscriptions change. The three keys are absent when they do not apply. A session on the server that
`whitelist_auto` chose which ends (`error`, `blocked`) keeps `purpose` and `whitelist_by_rule`, so that the window can
say which server it was that did not come up.

`resync` says that the service asked the panel for the subscription again because the session ended an attempt with
`no_server_answers` (in `reconnecting` or `error`; not for `offline`, `server_not_found` or `auth_rejected`; a
Expand All @@ -273,8 +275,9 @@ paths: a `reconnecting` session makes its next attempt at once
instead of waiting for the retry delay), `same` (a `304`, or the same paths: the retries go on as before, the cause
is more likely the network) or `failed` (the panel did not answer or refused). `resync_unix` is when the value was set.
Both keys stay while the session keeps trying, and are gone once it connects, is stopped or `connect` is called; they
are absent otherwise. A first `connect` that ended in `error` is not retried after `changed`: the person presses it
again.
are absent otherwise. A first `connect` that ended in `error` with `no_server_answers` gets one new attempt after
`changed`, as if the person pressed it again: the status goes to `connecting` and keeps `resync: "changed"` until that
attempt ends. If it fails too, the session stays in `error`.

`on_server_down` is about a server the person chose by name. `auto` has its own way round the paths: it picks a path at
every attempt (as above) and leaves out the paths that failed twice since the last success, until every path has had its
Expand Down
8 changes: 4 additions & 4 deletions ui/src/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export function liveHome(Base: typeof DCLogic): typeof DCLogic {
if (s.state === 'connected') {
Object.assign(next, { phase: 'on', secs: Math.max(0, Math.floor(Date.now() / 1000) - s.since_unix), wave: was === 'connecting' });
if (next.wave) { clearTimeout(this.t2); this.t2 = setTimeout(() => this.setState({ wave: false }), 1900); }
} else if (s.state === 'connecting') Object.assign(next, { phase: 'ing', cstep: STEP[s.step] ?? 0 });
} else if (s.state === 'connecting') Object.assign(next, { phase: 'ing', cstep: STEP[s.step] ?? 0, ...(s.resync === 'changed' ? { cs: 'rfnew' } : {}) }); // the attempt the new settings started
else if (s.state === 'reconnecting') Object.assign(next, { phase: 'ing', cs: s.error === 'offline' ? 'offline' : RESYNC[s.resync ?? ''] ?? 'rec' });
else if (s.state === 'blocked') Object.assign(next, { phase: 'off', cs: 'ks' });
else if (s.state === 'error' && s.error === 'no_subscription') next.phase = 'off';
Expand All @@ -394,8 +394,8 @@ export function liveHome(Base: typeof DCLogic): typeof DCLogic {
this.setState(next);
}

// How a session that ended in an error is shown. "New settings: connecting again" is not said here: an ended
// session is not retried, the person presses the button.
// How a session that ended in an error is shown. "New settings: connecting again" is said while that one new
// attempt runs (connecting); here it has ended too.
failed(s: Status): string { return s.resync === 'running' ? 'rf' : s.resync === 'same' ? 'rfsame' : 'error'; }

// ---- subscriptions
Expand Down Expand Up @@ -574,7 +574,7 @@ export function liveHome(Base: typeof DCLogic): typeof DCLogic {
// choice 'wl'. Shown those switches for one render, it words the card, the bar and the hover card in the window's
// language; the data is put in after.
wls(): Server[] { return this.subsList ? wlOf(this.sub()?.servers ?? []) : []; }
wlUsed(): boolean { const s: Status | null = this.live; return !!s && s.purpose === 'whitelist' && ['connected', 'connecting', 'reconnecting'].includes(s.state); }
wlUsed(): boolean { const s: Status | null = this.live; return !!s && s.purpose === 'whitelist' && (['connected', 'connecting', 'reconnecting'].includes(s.state) || s.state === 'error' && !!s.whitelist_by_rule); } // the rule's pick stays marked once it has ended
wlPicked(): boolean { const wls = this.wls(); return wls.length > 0 && (this.wlUsed() || wls.some((x) => x.id === this.st().sel)); }
renderVals() {
const wls = this.wls(), wlSel = this.wlPicked(), real = this.state;
Expand Down
Loading