Skip to content

Commit

Permalink
fix: Discard connection reset by peer
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 22, 2024
1 parent e1bd069 commit 6e92aa4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/crud/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log/slog"
"net/http"
"path"
"syscall"

absto "github.com/ViBiOh/absto/pkg/model"
"github.com/ViBiOh/fibr/pkg/provider"
Expand Down Expand Up @@ -183,18 +184,26 @@ func (s Service) Download(w http.ResponseWriter, r *http.Request, request provid
}

func (s Service) zipItems(ctx context.Context, done <-chan struct{}, request provider.Request, zipWriter *zip.Writer, items []absto.Item) (err error) {
defer func() {
if errors.Is(err, syscall.ECONNRESET) {
err = nil
}
}()

for _, item := range items {
select {
case <-done:
slog.ErrorContext(ctx, "context is done for zipping files")
return nil

default:
relativeURL := request.RelativeURL(item)

if !item.IsDir() {
if err = s.addFileToZip(ctx, zipWriter, item, relativeURL); err != nil {
return
}

continue
}

Expand Down

0 comments on commit 6e92aa4

Please sign in to comment.