Skip to content

Commit

Permalink
feat: no context timeout for coreserver handlers
Browse files Browse the repository at this point in the history
Using a specific timeout makes no sense and it makes it impossible
to iterate through every row.

The context is the request context and it is done when the client
aborts or the connection is closed.
  • Loading branch information
maeb committed Jan 6, 2024
1 parent 24ef9f4 commit b40ea68
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions server/coreserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (h Handler) search(w http.ResponseWriter, r *http.Request) {
log.Debug().Str("request", fmt.Sprintf("%+v", coreAPI)).Msgf("Found %d items in %s", count, time.Since(start))
}()

ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
ctx, cancel := context.WithCancel(r.Context())
defer cancel()

response := make(chan index.CdxResponse)
Expand Down Expand Up @@ -104,7 +104,7 @@ func (h Handler) listIds(w http.ResponseWriter, r *http.Request) {
}

response := make(chan index.IdResponse)
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
ctx, cancel := context.WithCancel(r.Context())
defer cancel()

if err := h.IdAPI.ListStorageRef(ctx, api.Request(coreAPI), response); err != nil {
Expand Down Expand Up @@ -172,7 +172,7 @@ func (h Handler) listFiles(w http.ResponseWriter, r *http.Request) {
return
}

ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
ctx, cancel := context.WithCancel(r.Context())
defer cancel()

responses := make(chan index.FileInfoResponse)
Expand Down Expand Up @@ -214,7 +214,7 @@ func (h Handler) getFileInfoByFilename(w http.ResponseWriter, r *http.Request) {
params := httprouter.ParamsFromContext(r.Context())
filename := params.ByName("filename")

ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
ctx, cancel := context.WithCancel(r.Context())
defer cancel()

fileInfo, err := h.FileAPI.GetFileInfo(ctx, filename)
Expand All @@ -235,9 +235,11 @@ func (h Handler) listCdxs(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
responses := make(chan index.CdxResponse)
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
ctx, cancel := context.WithCancel(r.Context())
defer cancel()

responses := make(chan index.CdxResponse)

if err := h.CdxAPI.Search(ctx, api.Request(coreAPI), responses); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Error().Err(err).Msg("Failed to list cdx records")
Expand Down Expand Up @@ -274,10 +276,7 @@ func (h Handler) loadRecordByUrn(w http.ResponseWriter, r *http.Request) {
params := httprouter.ParamsFromContext(r.Context())
warcId := params.ByName("urn")

ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()

record, err := h.WarcLoader.LoadById(ctx, warcId)
record, err := h.WarcLoader.LoadById(r.Context(), warcId)
if record != nil {
defer record.Close()
}
Expand Down

0 comments on commit b40ea68

Please sign in to comment.