|
| 1 | +# Login timeout fix moved to a separate branch |
| 2 | + |
| 3 | +Commit "Add experimental device code login" originally moved |
| 4 | +`context.WithTimeout(ctx, loginTimeout)` above `u2m.NewPersistentAuth` in |
| 5 | +`cmd/auth/login.go`. That move also fixes an existing bug unrelated to device |
| 6 | +code login, so it now lives on its own branch. |
| 7 | + |
| 8 | +## The bug |
| 9 | + |
| 10 | +`PersistentAuth` stores the context it is constructed with, and `Challenge()` |
| 11 | +takes no context. On `main` the timeout context is created after |
| 12 | +`NewPersistentAuth`, so the browser login never sees the deadline and waits |
| 13 | +for the OAuth redirect indefinitely: `auth login --timeout` has no effect on |
| 14 | +the browser step. This was introduced in `e619b01cf` (#2076), which changed |
| 15 | +`persistentAuth.Challenge(ctx)` to `persistentAuth.Challenge()`. The discovery |
| 16 | +login (#4702) already creates the timeout context first. |
| 17 | + |
| 18 | +## Where it went |
| 19 | + |
| 20 | +Branch `login-timeout`, commit `0fe7e106c` ("Apply auth login --timeout to the |
| 21 | +browser login"), based on `origin/main` (`f5801e2e3`): |
| 22 | + |
| 23 | +- `cmd/auth/login.go`: create the timeout context before `NewPersistentAuth`. |
| 24 | +- `acceptance/cmd/auth/login/timeout`: browser login with |
| 25 | + `BROWSER=echo_browser.py` (never completes the redirect) and `--timeout 1s` |
| 26 | + fails with `authorize: context deadline exceeded`. Without the fix the test |
| 27 | + hangs until the Go test timeout. |
| 28 | + |
| 29 | +Draft PR: https://github.com/databricks/cli/pull/7103. The changelog fragment |
| 30 | +`.nextchanges/cli/auth-login-timeout.md` is in commit `cfe4a88bb`. |
| 31 | + |
| 32 | +## What changed on this branch |
| 33 | + |
| 34 | +The timeout move is removed from the first commit, `0c5cafec9` ("Add |
| 35 | +experimental device code login"), so `device-code` is independent of |
| 36 | +`login-timeout` for now and matches `main` for this hunk. |
| 37 | + |
| 38 | +Until `device-code` is rebased on `login-timeout`, `--timeout` does not reach |
| 39 | +the device code flow either. The acceptance tests that depend on it are |
| 40 | +removed, from the commits that added them, for now: |
| 41 | + |
| 42 | +- `acceptance/cmd/auth/login/use-device-code-timeout`, from "Fix device |
| 43 | + authorization login timeout": a 5s-delayed device authorization request must |
| 44 | + be cancelled by `--timeout 1s`. That commit was later dropped (see below), |
| 45 | + so this test is gone with it. |
| 46 | +- The "Login times out while waiting for the confirmation code" case in |
| 47 | + `acceptance/cmd/auth/login/use-device-code/script`, from `34ed39b8a` ("Add |
| 48 | + tests for device code login") |
| 49 | + (`sleep 3 | ... --use-device-code --timeout 1s`, expecting |
| 50 | + `reading confirmation code: context deadline exceeded`). Without the fix it |
| 51 | + ends with `reading confirmation code: EOF` once stdin closes. Its |
| 52 | + `output.txt` was regenerated, which also shifts the `device-code-N` numbers |
| 53 | + in the recorded requests by one. |
| 54 | + |
| 55 | +The unit test `TestPromptForConfirmationCode_Timeout` stays: it passes the |
| 56 | +deadline to `promptForConfirmationCode` directly and does not depend on |
| 57 | +`login.go`. |
| 58 | + |
| 59 | +## Dropped commits |
| 60 | + |
| 61 | +Two follow-up commits were dropped from `device-code`. The old head with both |
| 62 | +is the local branch `backup/device-code-before-drop`. |
| 63 | + |
| 64 | +- "Fix device authorization login timeout": sent the device authorization |
| 65 | + request with the login context, so `--timeout` cancels it. Not needed: the |
| 66 | + HTTP client of `PersistentAuth` already times the request out after 30s |
| 67 | + (`libs/auth/u2m/persistent_auth.go`), so it only mattered for `--timeout` |
| 68 | + values under 30s. It also moved the form submission shared with the token |
| 69 | + exchange into a helper (`postDeviceCodeForm`). |
| 70 | +- "Reject extra auth login arguments before profile resolution": added |
| 71 | + `Args: cobra.MaximumNArgs(1)` to `auth login`. That changes behavior for all |
| 72 | + `auth login` users: on `main`, `auth login HOST PROFILE` silently uses HOST |
| 73 | + and ignores PROFILE. It is a candidate for its own PR with a changelog |
| 74 | + entry. Without it, the `existingProfile != nil` guard in the device-code |
| 75 | + preflight check (folded into `0c5cafec9`) is what prevents the crash with two |
| 76 | + positional arguments, so keep the guard until the argument check lands. |
| 77 | + |
| 78 | +## TODO: add the device code timeout test back |
| 79 | + |
| 80 | +After rebasing `device-code` on `login-timeout`, re-add the "Login times out |
| 81 | +while waiting for the confirmation code" case to |
| 82 | +`acceptance/cmd/auth/login/use-device-code/script` (copy it from |
| 83 | +`backup/device-code-timeout-tests`, after the "no confirmation code" case) and |
| 84 | +run `./task test-update` for `cmd/auth/login`. Do not check out the whole |
| 85 | +directory from the backup: its script also has the two-argument case, which |
| 86 | +depends on the dropped argument check. `use-device-code-timeout` needs the |
| 87 | +dropped "Fix device authorization login timeout" commit, so it is not coming |
| 88 | +back. `docs/device-code-login.md` already documents the |
| 89 | +`context deadline exceeded` error, which is only accurate once the |
| 90 | +`login-timeout` fix is in. |
0 commit comments