Add context timeouts for third-party requests
Some checks failed
/ golint (push) Failing after 3m56s

Avoid hanging a goroutine for a long time.
This commit is contained in:
Eli Ribble 2026-05-19 00:24:16 +00:00
parent 2093ea74c4
commit 15d8966971
No known key found for this signature in database
11 changed files with 80 additions and 5 deletions

View file

@ -11,6 +11,7 @@ import (
"net/http"
"os"
"path/filepath"
"time"
"github.com/Gleipnir-Technology/arcgis-go"
"github.com/Gleipnir-Technology/arcgis-go/fieldseeker"
@ -185,6 +186,9 @@ func getTileFlyover(ctx context.Context, w http.ResponseWriter, org *models.Orga
return writeTile(w, image)
}
func getTileSatellite(ctx context.Context, w http.ResponseWriter, z, y, x uint) error {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
map_service_id := "stadia"
map_service, err := models.TileServices.Query(
models.SelectWhere.TileServices.Name.EQ(map_service_id),
@ -218,6 +222,9 @@ func getTileSatellite(ctx context.Context, w http.ResponseWriter, z, y, x uint)
return writeTile(w, &tile)
}
func imageAtPoint(ctx context.Context, org *models.Organization, level uint, lat, lng float64) (*TileRaster, error) {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
fssync, err := getFieldseeker(ctx, org)
if err != nil {
return nil, fmt.Errorf("create fssync: %w", err)
@ -288,6 +295,9 @@ type TileRaster struct {
}
func ImageAtTile(ctx context.Context, org *models.Organization, level, y, x uint) (*TileRaster, error) {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
oauth, err := oauth.GetOAuthForOrg(ctx, org)
if err != nil {
return nil, fmt.Errorf("get oauth for org: %w", err)