Conversation
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR makes two improvements to the gateway system:
-
Heartbeat timing optimization: Moved heartbeat initialization from gateway startup to after successful relay connection establishment. This ensures the heartbeat only starts when the gateway can actually communicate with the relay server. The implementation uses a mutex-protected
startHeartbeatOnce()method to guarantee single initialization across reconnections. -
Enhanced user messaging: Improved the database proxy session message with clearer formatting and instructions, making it easier for users to understand how to connect to their database resource.
The changes are well-isolated, maintain backward compatibility, and follow good concurrency practices with proper mutex protection.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes are straightforward and well-implemented. The heartbeat refactoring improves reliability by ensuring it only starts after successful connection, and uses proper concurrency control. The message formatting changes are purely cosmetic with no behavioral impact. No security, logic, or syntax issues found.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/gateway-v2/gateway.go | 5/5 | Refactored heartbeat initialization to start after relay connection is established, with proper mutex protection to ensure single initialization |
| packages/pam/local-database-proxy.go | 5/5 | Enhanced user-facing output with better formatted connection instructions |
Sequence Diagram
sequenceDiagram
participant Start as Gateway.Start()
participant Connect as connectAndServe()
participant Retry as connectWithRetry()
participant Heartbeat as startHeartbeatOnce()
participant HB as registerHeartBeat()
participant Relay as Relay Server
Start->>Start: Create errCh channel
Start->>Start: Start certificate renewal
Start->>Start: Start session uploader
Start->>Connect: Call connectAndServe(ctx, errCh)
Connect->>Connect: Register gateway
Connect->>Retry: Call connectWithRetry(ctx, errCh)
loop Retry up to 6 attempts
Retry->>Relay: Attempt SSH connection
alt Connection fails
Relay-->>Retry: Error
Retry->>Retry: Wait and retry
else Connection succeeds
Relay-->>Retry: SSH client established
Retry->>Heartbeat: Call startHeartbeatOnce(ctx, errCh)
Heartbeat->>Heartbeat: Lock heartbeatMu
alt !heartbeatStarted
Heartbeat->>HB: registerHeartBeat(ctx, errCh)
Heartbeat->>Heartbeat: Set heartbeatStarted = true
HB->>HB: Start goroutine
Note over HB: Phase 1: Retry every 10s until success
Note over HB: Phase 2: Regular heartbeat every 30min
end
Heartbeat->>Heartbeat: Unlock heartbeatMu
Retry->>Retry: Handle connection
end
end
2 files reviewed, no comments
Description 📣
Make heartbeat run after relay connection & improve user-facing message after accessing an account