Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ The release notes should contain at least the following sections:

## Important information

* The `timeout` configuration flag is now enforced consistently on all HTTP calls. This means that some slow calls that were previously successful will now be cancelled. Please review the value to be applied (the default is 10 seconds) and, if needed, update it to suit your needs.

## Minimal database schema version

| Schema | CockroachDB | Yugabyte |
Expand Down
16 changes: 13 additions & 3 deletions cmds/core-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,11 @@ func createRIDServers(ctx context.Context, locality string, logger *zap.Logger)
app := application.NewFromTransactor(ridStore, logger)
return &rid_v1.Server{
App: app,
Timeout: *timeout,
Locality: locality,
AllowHTTPBaseUrls: *allowHTTPBaseUrls,
Cron: ridCron,
}, &rid_v2.Server{
App: app,
Timeout: *timeout,
Locality: locality,
AllowHTTPBaseUrls: *allowHTTPBaseUrls,
Cron: ridCron,
Expand Down Expand Up @@ -226,7 +224,6 @@ func createSCDServer(ctx context.Context, logger *zap.Logger) (*scd.Server, erro
return &scd.Server{
Store: scdStore,
DSSReportHandler: &scd.JSONLoggingReceivedReportHandler{ReportLogger: logger},
Timeout: *timeout,
AllowHTTPBaseUrls: *allowHTTPBaseUrls,
}, nil
}
Expand Down Expand Up @@ -315,6 +312,7 @@ func RunHTTPServer(ctx context.Context, ctxCanceler func(), address, locality st
handler := healthyEndpointMiddleware(logger, &multiRouter)
handler = logging.HTTPMiddleware(logger, *dumpRequests, handler)
handler = authorizer.TokenMiddleware(handler)
handler = timeoutMiddleware(*timeout, handler)

if *enableOpenTelemetry {
httpSpanName := func(operation string, req *http.Request) string {
Expand Down Expand Up @@ -384,6 +382,18 @@ func healthyEndpointMiddleware(logger *zap.Logger, next http.Handler) http.Handl
})
}

func timeoutMiddleware(timeout time.Duration, next http.Handler) http.Handler {

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()

r = r.WithContext(ctx)

next.ServeHTTP(w, r)
})
}

func SetDeprecatingHttpFlag(logger *zap.Logger, newFlag **bool, deprecatedFlag **bool) {
if **deprecatedFlag {
logger.Warn("DEPRECATED: enable_http has been renamed to allow_http_base_urls.")
Expand Down
10 changes: 0 additions & 10 deletions pkg/aux_/store/datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datastore

import (
"context"
"time"

"github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/interuss/dss/pkg/datastore/flags"
Expand All @@ -28,13 +27,6 @@ const (
var (
// DefaultClock is what is used as the Store's clock, returned from Dial.
DefaultClock = clockwork.NewRealClock()
// DefaultTimeout is the timeout applied to the txn retrier.
// Note that this is not applied everywhere, but only
// on the txn retrier.
// If a given deadline is already supplied on the context, the earlier
// deadline is used
// TODO: use this in other function calls
DefaultTimeout = 10 * time.Second
)

type repo struct {
Expand Down Expand Up @@ -121,8 +113,6 @@ func (s *Store) Transact(ctx context.Context, f func(repo repos.Repository) erro
// TODO: consider what tx opts we want to support.
// TODO: we really need to remove the upper cockroach package, and have one
// "store" for everything
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()

ctx = crdb.WithMaxRetries(ctx, flags.ConnectParameters().MaxRetries)

Expand Down
11 changes: 0 additions & 11 deletions pkg/rid/server/v1/isa_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func (s *Server) GetIdentificationServiceArea(ctx context.Context, req *restapi.
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
isa, err := s.App.GetISA(ctx, id)
if err != nil {
return restapi.GetIdentificationServiceAreaResponseSet{Response500: &api.InternalServerErrorBody{
Expand All @@ -56,9 +54,6 @@ func (s *Server) CreateIdentificationServiceArea(ctx context.Context, req *resta
return resp
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.CreateIdentificationServiceAreaResponseSet{Response403: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing owner"))}}
Expand Down Expand Up @@ -145,8 +140,6 @@ func (s *Server) UpdateIdentificationServiceArea(ctx context.Context, req *resta
return restapi.UpdateIdentificationServiceAreaResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.PropagateWithCode(err, dsserr.BadRequest, "Invalid version"))}}
}
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.UpdateIdentificationServiceAreaResponseSet{Response403: &restapi.ErrorResponse{
Expand Down Expand Up @@ -238,8 +231,6 @@ func (s *Server) DeleteIdentificationServiceArea(ctx context.Context, req *resta
return restapi.DeleteIdentificationServiceAreaResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
isa, subscribers, err := s.App.DeleteISA(ctx, id, dssmodels.Owner(*req.Auth.ClientID), version)
if err != nil {
err = stacktrace.Propagate(err, "Could not delete ISA")
Expand Down Expand Up @@ -312,8 +303,6 @@ func (s *Server) SearchIdentificationServiceAreas(ctx context.Context, req *rest
latest = &ts
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
isas, err := s.App.SearchISAs(ctx, cu, earliest, latest)
if err != nil {
err = stacktrace.Propagate(err, "Unable to search ISAs")
Expand Down
2 changes: 0 additions & 2 deletions pkg/rid/server/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1

import (
"context"
"time"

"github.com/interuss/dss/pkg/api"
restapi "github.com/interuss/dss/pkg/api/ridv1"
Expand All @@ -16,7 +15,6 @@ import (
// Server implements ridv1.Implementation.
type Server struct {
App application.App
Timeout time.Duration
Locality string
AllowHTTPBaseUrls bool
Cron *cron.Cron
Expand Down
13 changes: 0 additions & 13 deletions pkg/rid/server/v1/subscription_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func (s *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
return restapi.DeleteSubscriptionResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}
// TODO: put the context with timeout into an interceptor so it's always set.
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
subscription, err := s.App.DeleteSubscription(ctx, id, dssmodels.Owner(*req.Auth.ClientID), version)
if err != nil {
err = stacktrace.Propagate(err, "Could not delete Subscription")
Expand Down Expand Up @@ -92,8 +89,6 @@ func (s *Server) SearchSubscriptions(ctx context.Context, req *restapi.SearchSub
Message: dsserr.Handle(ctx, stacktrace.PropagateWithCode(err, dsserr.BadRequest, "Invalid area"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
subscriptions, err := s.App.SearchSubscriptionsByOwner(ctx, cu, dssmodels.Owner(*req.Auth.ClientID))
if err != nil {
err = stacktrace.Propagate(err, "Could not search Subscriptions")
Expand Down Expand Up @@ -131,8 +126,6 @@ func (s *Server) GetSubscription(ctx context.Context, req *restapi.GetSubscripti
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
subscription, err := s.App.GetSubscription(ctx, id)
if err != nil {
return restapi.GetSubscriptionResponseSet{Response500: &api.InternalServerErrorBody{
Expand All @@ -156,9 +149,6 @@ func (s *Server) CreateSubscription(ctx context.Context, req *restapi.CreateSubs
return resp
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.CreateSubscriptionResponseSet{Response403: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing owner"))}}
Expand Down Expand Up @@ -268,9 +258,6 @@ func (s *Server) UpdateSubscription(ctx context.Context, req *restapi.UpdateSubs
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.UpdateSubscriptionResponseSet{Response403: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing owner"))}}
Expand Down
11 changes: 0 additions & 11 deletions pkg/rid/server/v2/isa_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ func (s *Server) GetIdentificationServiceArea(ctx context.Context, req *restapi.
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
isa, err := s.App.GetISA(ctx, id)
if err != nil {
return restapi.GetIdentificationServiceAreaResponseSet{Response500: &api.InternalServerErrorBody{
Expand All @@ -54,9 +52,6 @@ func (s *Server) CreateIdentificationServiceArea(ctx context.Context, req *resta
return resp
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.CreateIdentificationServiceAreaResponseSet{Response403: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing owner"))}}
Expand Down Expand Up @@ -138,8 +133,6 @@ func (s *Server) UpdateIdentificationServiceArea(ctx context.Context, req *resta
return restapi.UpdateIdentificationServiceAreaResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.PropagateWithCode(err, dsserr.BadRequest, "Invalid version"))}}
}
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.UpdateIdentificationServiceAreaResponseSet{Response403: &restapi.ErrorResponse{
Expand Down Expand Up @@ -227,8 +220,6 @@ func (s *Server) DeleteIdentificationServiceArea(ctx context.Context, req *resta
return restapi.DeleteIdentificationServiceAreaResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
isa, subscribers, err := s.App.DeleteISA(ctx, id, dssmodels.Owner(*req.Auth.ClientID), version)
if err != nil {
err = stacktrace.Propagate(err, "Could not delete ISA")
Expand Down Expand Up @@ -300,8 +291,6 @@ func (s *Server) SearchIdentificationServiceAreas(ctx context.Context, req *rest
latest = &ts
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
isas, err := s.App.SearchISAs(ctx, cu, earliest, latest)
if err != nil {
err = stacktrace.Propagate(err, "Unable to search ISAs")
Expand Down
2 changes: 0 additions & 2 deletions pkg/rid/server/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"context"
"time"

"github.com/interuss/dss/pkg/api"
restapi "github.com/interuss/dss/pkg/api/ridv2"
Expand All @@ -16,7 +15,6 @@ import (
// Server implements ridv2.Implementation.
type Server struct {
App application.App
Timeout time.Duration
Locality string
AllowHTTPBaseUrls bool
Cron *cron.Cron
Expand Down
13 changes: 0 additions & 13 deletions pkg/rid/server/v2/subscription_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (s *Server) DeleteSubscription(ctx context.Context, req *restapi.DeleteSubs
return restapi.DeleteSubscriptionResponseSet{Response400: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}
// TODO: put the context with timeout into an interceptor so it's always set.
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
subscription, err := s.App.DeleteSubscription(ctx, id, dssmodels.Owner(*req.Auth.ClientID), version)
if err != nil {
err = stacktrace.Propagate(err, "Could not delete Subscription")
Expand Down Expand Up @@ -90,8 +87,6 @@ func (s *Server) SearchSubscriptions(ctx context.Context, req *restapi.SearchSub
Message: dsserr.Handle(ctx, stacktrace.PropagateWithCode(err, dsserr.BadRequest, "Invalid area"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
subscriptions, err := s.App.SearchSubscriptionsByOwner(ctx, cu, dssmodels.Owner(*req.Auth.ClientID))
if err != nil {
err = stacktrace.Propagate(err, "Could not search Subscriptions")
Expand Down Expand Up @@ -128,8 +123,6 @@ func (s *Server) GetSubscription(ctx context.Context, req *restapi.GetSubscripti
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
subscription, err := s.App.GetSubscription(ctx, id)
if err != nil {
return restapi.GetSubscriptionResponseSet{Response500: &api.InternalServerErrorBody{
Expand All @@ -152,9 +145,6 @@ func (s *Server) CreateSubscription(ctx context.Context, req *restapi.CreateSubs
return resp
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.CreateSubscriptionResponseSet{Response403: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing owner"))}}
Expand Down Expand Up @@ -259,9 +249,6 @@ func (s *Server) UpdateSubscription(ctx context.Context, req *restapi.UpdateSubs
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Invalid ID format"))}}
}

ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()

if req.Auth.ClientID == nil {
return restapi.UpdateSubscriptionResponseSet{Response403: &restapi.ErrorResponse{
Message: dsserr.Handle(ctx, stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Missing owner"))}}
Expand Down
10 changes: 0 additions & 10 deletions pkg/rid/store/datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datastore

import (
"context"
"time"

"github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/interuss/dss/pkg/datastore/flags"
Expand All @@ -28,13 +27,6 @@ const (
var (
// DefaultClock is what is used as the Store's clock, returned from Dial.
DefaultClock = clockwork.NewRealClock()
// DefaultTimeout is the timeout applied to the txn retrier.
// Note that this is not applied everywhere, but only
// on the txn retrier.
// If a given deadline is already supplied on the context, the earlier
// deadline is used
// TODO: use this in other function calls
DefaultTimeout = 10 * time.Second
)

type repo struct {
Expand Down Expand Up @@ -119,8 +111,6 @@ func (s *Store) Transact(ctx context.Context, f func(repo repos.Repository) erro
// TODO: consider what tx opts we want to support.
// TODO: we really need to remove the upper cockroach package, and have one
// "store" for everything
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()

ctx = crdb.WithMaxRetries(ctx, flags.ConnectParameters().MaxRetries)

Expand Down
4 changes: 0 additions & 4 deletions pkg/rid/store/datastore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ var (
writer = "writer"
)

func init() {
DefaultTimeout = 500 * time.Millisecond
}

func setUpStore(ctx context.Context, t *testing.T) (*Store, func()) {
connectParameters := flags.ConnectParameters()
if connectParameters.Host == "" || connectParameters.Port == 0 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/scd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scd

import (
"context"
"time"

"github.com/interuss/dss/pkg/api"
restapi "github.com/interuss/dss/pkg/api/scdv1"
Expand Down Expand Up @@ -37,7 +36,6 @@ func makeSubscribersToNotify(subscriptions []*scdmodels.Subscription) []restapi.
type Server struct {
Store scdstore.Store
DSSReportHandler ReceivedReportHandler
Timeout time.Duration
AllowHTTPBaseUrls bool
}

Expand Down
Loading