nginx and upstream prematurely closed connection while reading upstream

41 views
Skip to first unread message

wilk

unread,
Aug 18, 2017, 11:19:59 AM8/18/17
to golan...@googlegroups.com
Hi,

I'm experiencing a lot of log in nginx :
upstream prematurely closed connection while reading upstream

Looking in my code it's because I added

w.Header().Set("content-length", strconv.Itoa(len(w.Body.Bytes())))
If i remove it, no more logs and my clients are happy again

I use an httptest.ResponseRecorder as a response buffer.

then write the headers (content type and cookies), write the code and
write the body wrt.Write(w.Body.Bytes()). Nothing special, if i look
with curl the content-lenght seems to be ok.

I don't see where i did a mistake, and it's difficult to find because
i cannot reproduce it localy.

Thanks

--
William

wilk

unread,
Aug 19, 2017, 10:19:44 AM8/19/17
to golan...@googlegroups.com
On 18-08-2017, wilk wrote:
> Hi,
>
> I'm experiencing a lot of log in nginx :
> upstream prematurely closed connection while reading upstream
>
> Looking in my code it's because I added
>
> w.Header().Set("content-length", strconv.Itoa(len(w.Body.Bytes())))
> If i remove it, no more logs and my clients are happy again

I answer to myself, i was setting content-length even on redirect

--
William

Reply all
Reply to author
Forward
0 new messages