openKeyringWithTimeoutFunc prevents an unresponsive SecretService open from blocking the CLI indefinitely. The worker goroutine may remain blocked until process exit after a timeout.
( cfg keyring.Config, timeout time.Duration, hint string, open func(keyring.Config) (keyring.Keyring, error), )
| 338 | // blocking the CLI indefinitely. The worker goroutine may remain blocked until |
| 339 | // process exit after a timeout. |
| 340 | func openKeyringWithTimeoutFunc( |
| 341 | cfg keyring.Config, |
| 342 | timeout time.Duration, |
| 343 | hint string, |
| 344 | open func(keyring.Config) (keyring.Keyring, error), |
| 345 | ) (keyring.Keyring, error) { |
| 346 | ch := make(chan keyringResult, 1) |
| 347 | |
| 348 | go func() { |
| 349 | ring, err := open(cfg) |
| 350 | ch <- keyringResult{ring, err} |
| 351 | }() |
| 352 | |
| 353 | select { |
| 354 | case res := <-ch: |
| 355 | if res.err != nil { |
| 356 | return nil, fmt.Errorf("open keyring: %w", res.err) |
| 357 | } |
| 358 | |
| 359 | return res.ring, nil |
| 360 | case <-time.After(timeout): |
| 361 | return nil, keyringTimeoutError("opening keyring", timeout, hint) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func Open(options OpenOptions) (Repository, error) { |
| 366 | ring, err := openKeyringWithOptions(options) |