Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers timeout on POST requests #856

Closed
artur-ma opened this issue Jun 30, 2021 · 1 comment
Closed

Headers timeout on POST requests #856

artur-ma opened this issue Jun 30, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@artur-ma
Copy link
Contributor

artur-ma commented Jun 30, 2021

Bug Description

POST requests that are done via undici throws "headers timeout error", when requesting simple golang server built on top of fasthttp lib (https://github.com/valyala/fasthttp), it does work with Postman and got client

Reproducible By

Go Server

package main

import (
	"fmt"
	"github.com/fasthttp/router"
	"github.com/valyala/fasthttp"
)

func route(h *handler) *router.Router {
	router := router.New()
	router.POST("/testPost", h.testHandler)
	return router
}

func (h *handler) testHandler(ctx *fasthttp.RequestCtx) {
	defer fmt.Println(`response`)
	
	ctx.SetContentType(`application/json`)
	ctx.SetStatusCode(200)
	ctx.SetBody([]byte(`{}`))
	
	return
}

type handler struct {
}

func newHandler() *handler {
	return &handler{}
}


func main() {
	h := newHandler()
	r := route(h)
	fasthttp.ListenAndServe(`:8989`, r.Handler)
}

undici request

request('http://localhost:8989/testPost', { method: 'POST', body: '{}' }).then(r => console.log('done').catch(e => console.error(e)))

will fail with

HeadersTimeoutError: Headers Timeout Error
    at Timeout.onParserTimeout [as _onTimeout] (<>/node_modules/undici/lib/client.js:955:28)
    at listOnTimeout (internal/timers.js:556:17)
    at processTimers (internal/timers.js:497:7) {
  code: 'UND_ERR_HEADERS_TIMEOUT'
}

Expected Behavior

Resolve and get the response as other clients

Environment

Node v14.16.1
OS 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
Undici: 4.0.0

Additional context

Get requests work as expected

I do see Post requests arrive to the server, but looks like undici can not get the response

This is not actual timeout issue, Postman and got finishes this request in about ~3ms
undici waits couple of seconds before the error is thrown

@artur-ma artur-ma added the bug Something isn't working label Jun 30, 2021
@artur-ma artur-ma changed the title Request does not resolve Headers timeout on POST requests Jun 30, 2021
@artur-ma
Copy link
Contributor Author

ok, looks like I was missing SetConnectionClose on the server side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant