Skip to content

Commit 94be888

Browse files
fix: reduce connection timeouts for Kafka/Redis/Temporal to prevent CI test timeout
- Kafka: add 3s context timeout for DialContext (was using parent context with no timeout) - Redis: set MaxRetries=1 (was default 5), reduce MinIdleConns to 2, reduce DialTimeout to 2s - Temporal: use NewLazyClient + 3s CheckHealth instead of blocking Dial; close client on health check failure Tests now complete in ~36s locally (was timing out at 60s in CI) Co-Authored-By: Patrick Munis <pmunis@gmail.com>
1 parent 32905fe commit 94be888

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

services/gateway/internal/kafka/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ func (c *Client) connect() {
8181
Async: false,
8282
}
8383

84-
conn, err := kafka.DialContext(c.ctx, "tcp", c.brokers)
84+
dialCtx, dialCancel := context.WithTimeout(c.ctx, 3*time.Second)
85+
defer dialCancel()
86+
conn, err := kafka.DialContext(dialCtx, "tcp", c.brokers)
8587
if err != nil {
8688
log.Printf("[Kafka] WARN: Cannot reach %s: %v — running in fallback mode (in-memory dispatch)", c.brokers, err)
8789
c.mu.Lock()

services/gateway/internal/redis/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ func (c *Client) connect() {
7272
Addr: c.url,
7373
Password: c.password,
7474
DB: 0,
75-
DialTimeout: 3 * time.Second,
75+
DialTimeout: 2 * time.Second,
7676
ReadTimeout: 2 * time.Second,
7777
WriteTimeout: 2 * time.Second,
7878
PoolSize: 20,
79-
MinIdleConns: 5,
79+
MinIdleConns: 2,
80+
MaxRetries: 1, // Fail fast — don't retry 5 times on initial connect
8081
}
8182
rdb := goredis.NewClient(opts)
8283

services/gateway/internal/temporal/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ func NewClient(host string) *Client {
5757
func (c *Client) connect() {
5858
log.Printf("[Temporal] Connecting to %s", c.host)
5959

60-
// Create real Temporal SDK client
61-
sdkClient, err := client.Dial(client.Options{
60+
// Create real Temporal SDK client with short connection timeout
61+
dialCtx, dialCancel := context.WithTimeout(c.ctx, 3*time.Second)
62+
defer dialCancel()
63+
sdkClient, err := client.NewLazyClient(client.Options{
6264
HostPort: c.host,
6365
Namespace: "nexcom",
6466
})
67+
if err == nil {
68+
// Verify connectivity with a quick health check
69+
_, err = sdkClient.CheckHealth(dialCtx, &client.CheckHealthRequest{})
70+
}
6571
if err != nil {
6672
log.Printf("[Temporal] WARN: Cannot reach %s: %v — running in fallback mode (in-memory workflows)", c.host, err)
73+
if sdkClient != nil {
74+
sdkClient.Close()
75+
}
6776
c.mu.Lock()
6877
c.fallbackMode = true
6978
c.connected = false

0 commit comments

Comments
 (0)