Skip to content

Commit 1e6899f

Browse files
committed
fix: add better context and timeout for db related queries
1 parent 779260e commit 1e6899f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cli/server.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,10 @@ func templateHelpers(options *coderd.Options) map[string]any {
13101310
"base_url": func() string { return options.AccessURL.String() },
13111311
"current_year": func() string { return strconv.Itoa(time.Now().Year()) },
13121312
"logo_url": func() string {
1313-
logoURL, err := options.Database.GetLogoURL(context.Background())
1313+
ctx, cancel := context.WithTimeout(context.Background(), 1 * time.Second)
1314+
defer cancel()
1315+
1316+
logoURL, err := options.Database.GetLogoURL(ctx)
13141317
if err != nil {
13151318
if errors.Is(err, sql.ErrNoRows) {
13161319
return notifications.NotificationsDefaultLogoURL
@@ -1322,7 +1325,10 @@ func templateHelpers(options *coderd.Options) map[string]any {
13221325
return logoURL
13231326
},
13241327
"app_name": func() string {
1325-
appName, err := options.Database.GetApplicationName(context.Background())
1328+
ctx, cancel := context.WithTimeout(context.Background(), 1 * time.Second)
1329+
defer cancel()
1330+
1331+
appName, err := options.Database.GetApplicationName(ctx)
13261332
if err != nil {
13271333
if errors.Is(err, sql.ErrNoRows) {
13281334
return notifications.NotificationsDefaultAppName

0 commit comments

Comments
 (0)