Skip to content

[duplicate-code] Duplicate Code Pattern: Session Timeout Env-Var Literal #5071

@github-actions

Description

@github-actions

Part of duplicate code analysis: #5070

Summary

envutil.GetEnvDuration("MCP_GATEWAY_SESSION_TIMEOUT", 6*time.Hour) appears as a raw literal in internal/server/transport.go even though internal/server/routed.go already defines a dedicated wrapper getRoutedSessionTimeout() for the same call. If the env-var name, default value, or behaviour ever changes, the developer must remember to update both files.

Duplication Details

Pattern: Repeated env-var call for session timeout

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • internal/server/transport.go (line 43) — inline in sdk.StreamableHTTPOptions literal
    • internal/server/routed.go (line 128) — wrapped in getRoutedSessionTimeout()
  • Code Sample:
// transport.go (duplicated literal)
SessionTimeout: envutil.GetEnvDuration("MCP_GATEWAY_SESSION_TIMEOUT", 6*time.Hour),

// routed.go (canonical wrapper – already exists)
func getRoutedSessionTimeout() time.Duration {
    return envutil.GetEnvDuration("MCP_GATEWAY_SESSION_TIMEOUT", 6*time.Hour)
}

Impact Analysis

  • Maintainability: Medium — two places to update if the env-var key or default changes.
  • Bug Risk: Low — divergence only manifests if one site is updated without the other.
  • Code Bloat: Low — one line, but the pattern sets a bad precedent.

Refactoring Recommendations

  1. Move getRoutedSessionTimeout to session.go or a new server/config.go (or rename to getSessionTimeout) so both transport.go and routed.go can call it.

    • Estimated effort: < 30 minutes
    • Benefits: single source of truth; existing test TestGetRoutedSessionTimeout continues to cover both callers.
  2. Alternatively, promote it to a package-level exported helper SessionTimeout() if callers outside internal/server ever need it.

Implementation Checklist

  • Rename / move getRoutedSessionTimeout() to a shared location within internal/server
  • Update transport.go to call the shared helper
  • Verify existing TestGetRoutedSessionTimeout still passes
  • Run make test-unit

Parent Issue

See parent analysis report: #5070
Related to #5070

Generated by Duplicate Code Detector · ● 960.3K ·

  • expires on May 11, 2026, 6:28 AM UTC

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions