Commit 57fc2cf
authored
[Repo Assist] fix(mcp): replace hardcoded 30s with defaultConnectTimeout constant, fix <= 0 guard (#3946)
🤖 *This is a Repo Assist automated pull request.*
## Summary
Closes #3933.
Two locations in `internal/mcp/connection.go` used the magic literal `30
* time.Second` for the HTTP connect-timeout fallback. A canonical
constant `config.DefaultConnectTimeout = 30` already exists in
`internal/config/config_core.go`, but importing that package into
`internal/mcp` would pull in `init()` functions with side effects.
Instead, this PR introduces a local unexported constant to be the single
source of truth within the package.
It also fixes a latent bug: `reconnectSDKTransport` guarded with `== 0`,
which left negative values through as-is. The guard is now `<= 0`,
consistent with `NewHTTPConnection`.
## Root cause
Issue #3933 (Duplicate Code Detector) identified:
- `NewHTTPConnection` (line ~202): `if connectTimeout <= 0 {
connectTimeout = 30 * time.Second }`
- `reconnectSDKTransport` (line ~386): `if timeout == 0 { timeout = 30 *
time.Second }` — note inconsistent guard
Both hardcode 30 s instead of using a named constant, and the guards
differ.
## Changes
| File | Change |
|------|--------|
| `internal/mcp/connection.go` | Add `const defaultConnectTimeout = 30 *
time.Second`; replace both magic literals with the constant; fix `== 0`
→ `<= 0` guard in `reconnectSDKTransport` |
## Trade-offs
- **Why a local constant, not importing `config`?** `internal/config`
has `init()` functions that register flags and load schemas. Importing
it into `internal/mcp` just for one constant would be a heavyweight
dependency and could cause ordering surprises. A comment on the constant
explicitly documents the sync requirement.
- **Behavioural change:** A negative `connectTimeout` passed to
`reconnectSDKTransport` previously slipped through; it now falls back to
30 s. This is the correct behaviour (negative durations are invalid) and
consistent with `NewHTTPConnection`.
## Test Status
1 file changed
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
199 | 204 | | |
200 | 205 | | |
201 | 206 | | |
202 | | - | |
| 207 | + | |
203 | 208 | | |
204 | 209 | | |
205 | 210 | | |
| |||
379 | 384 | | |
380 | 385 | | |
381 | 386 | | |
382 | | - | |
383 | | - | |
| 387 | + | |
| 388 | + | |
384 | 389 | | |
385 | 390 | | |
386 | 391 | | |
| |||
0 commit comments