Skip to content

Commit feb1e6b

Browse files
committed
Fix timeout issues with chunked queries
- Increase timeout from 20min to 30min for large queries - Increase HTTP client timeout from 15min to 30min - Reduce chunk size from 3 days to 1 day to prevent individual chunk timeouts - This addresses the 'context deadline exceeded' errors reported by maintainer The smaller chunks with longer timeouts should resolve the timeout issues while still providing the benefits of chunking for large datasets.
1 parent a1d0c1f commit feb1e6b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

backend/internal/handlers/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ func (h *Handlers) GetNetworkLogs(c *gin.Context) {
111111
// Use chunking for queries longer than 7 days to prevent response size issues
112112
if duration > 7*24*time.Hour {
113113
// Use smaller chunks and fewer parallel requests for 30+ day queries
114-
chunkSize := 3 * 24 * time.Hour // 3-day chunks instead of 6-hour
115-
maxParallel := 2 // Reduce parallel requests to prevent memory issues
114+
chunkSize := 24 * time.Hour // 1-day chunks to prevent timeouts
115+
maxParallel := 2 // Reduce parallel requests to prevent memory issues
116116
chunks, err := h.tailscaleService.GetNetworkLogsChunkedParallel(start, end, chunkSize, maxParallel)
117117
if err != nil {
118118
c.JSON(http.StatusInternalServerError, gin.H{

backend/internal/services/tailscale.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewTailscaleService(cfg *config.Config) *TailscaleService {
8787
} else if cfg.TailscaleAPIKey != "" {
8888
ts.apiKey = cfg.TailscaleAPIKey
8989
ts.client = &http.Client{
90-
Timeout: 15 * time.Minute, // Increased timeout for large requests
90+
Timeout: 30 * time.Minute, // Much longer timeout for large requests
9191
}
9292
ts.tsClient = &tailscale.Client{
9393
APIKey: cfg.TailscaleAPIKey,
@@ -96,7 +96,7 @@ func NewTailscaleService(cfg *config.Config) *TailscaleService {
9696
ts.useOAuth = false
9797
} else {
9898
ts.client = &http.Client{
99-
Timeout: 15 * time.Minute, // Increased timeout for large requests
99+
Timeout: 30 * time.Minute, // Much longer timeout for large requests
100100
}
101101
}
102102

@@ -257,10 +257,10 @@ func (ts *TailscaleService) GetNetworkLogs(start, end string) (interface{}, erro
257257

258258
// For smaller ranges, use the original approach
259259
if ts.tsClient != nil {
260-
// Use longer timeout for larger time ranges
260+
// Use much longer timeout for larger time ranges
261261
timeoutDuration := 10 * time.Minute
262262
if endTime.Sub(startTime) > 7*24*time.Hour {
263-
timeoutDuration = 20 * time.Minute // Longer timeout for 30+ day queries
263+
timeoutDuration = 30 * time.Minute // Much longer timeout for 30+ day queries
264264
}
265265
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
266266
defer cancel()
@@ -292,10 +292,10 @@ func (ts *TailscaleService) GetNetworkLogs(start, end string) (interface{}, erro
292292
endpoint += fmt.Sprintf("?start=%s&end=%s", url.QueryEscape(start), url.QueryEscape(end))
293293
}
294294

295-
// Use longer timeout for larger time ranges
295+
// Use much longer timeout for larger time ranges
296296
timeoutDuration := 10 * time.Minute
297297
if endTime.Sub(startTime) > 7*24*time.Hour {
298-
timeoutDuration = 20 * time.Minute // Longer timeout for 30+ day queries
298+
timeoutDuration = 30 * time.Minute // Much longer timeout for 30+ day queries
299299
}
300300
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
301301
defer cancel()

0 commit comments

Comments
 (0)