Skip to content

Commit

Permalink
removes timeout from HTTP server
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Calza <[email protected]>
  • Loading branch information
brunocalza committed Feb 7, 2024
1 parent 1ec5f4b commit b2d02c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 6 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func (h *Handlers) Upload(rw http.ResponseWriter, r *http.Request) {
Shard: result.Shard.String(),
}

bytes, _ := json.Marshal(response)
bytes, err := json.Marshal(response)
if err != nil {
slog.Error("json marshalling", err)

Check failure on line 56 in handlers.go

View workflow job for this annotation

GitHub Actions / lint

`marshalling` is a misspelling of `marshaling` (misspell)
rw.WriteHeader(http.StatusInternalServerError)
return
}
_, _ = rw.Write(bytes)
}

Expand Down
7 changes: 2 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ func main() {
router.get("/api/v1/health", handlers.Health)

srv := &http.Server{
Addr: fmt.Sprintf("0.0.0.0:%s", cfg.HTTP.Port),
WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15,
IdleTimeout: time.Second * 60,
Handler: router.r,
Addr: fmt.Sprintf("0.0.0.0:%s", cfg.HTTP.Port),
Handler: router.r,
}

// Run our server in a goroutine so that it doesn't block.
Expand Down
7 changes: 1 addition & 6 deletions uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,11 @@ func newW3sclient(sk string, proofBytes []byte) (*w3sclient, error) {
}

func (c *w3sclient) upload(root cid.Cid, dest string) (cid.Cid, error) {
// no need to close the file here, because the http client will do.
f, err := os.Open(fmt.Sprintf("%s.car", dest))
if err != nil {
return cid.Undef, err
}
defer func() {
if err := f.Close(); err != nil {
slog.Error("close file", err)
}
}()

stat, err := f.Stat()
if err != nil {
Expand Down Expand Up @@ -297,7 +293,6 @@ func (c *w3sclient) upload(root cid.Cid, dest string) (cid.Cid, error) {
for k, v := range rcpt.Out().Ok().Headers.Values {
hdr[k] = []string{v}
}

hr.Header = hdr
hr.ContentLength = int64(size)
httpClient := http.Client{
Expand Down

0 comments on commit b2d02c2

Please sign in to comment.