ninenines / cowboy

Small, fast, modern HTTP server for Erlang/OTP.

Home Page:https://ninenines.eu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibly incorrect behavior on pipelined request shutdown

dmitrivereshchagin opened this issue · comments

Current behavior of cowboy_http:initiate_closing/2 seems strange to me. It calls cowboy_stream:terminate/3 for all streams in #state.streams except the first one. It seems like the intention was to terminate all but the stream currently being processed. This is not guaranteed as the first stream in this list is the last created one.

cowboy_stream:terminate/3 is also called from cowboy_http:terminate/2. Thus it can be called twice for some streams. It makes cowboy_stream_h to call metrics callback twice for the same request.

Another possible issue is that cowboy_http:stream_next/1 doesn't check if the last_streamid has been reached. This may cause next response to be written after Cowboy sends "close" connection option. Seems like Gun hides this in tests. It's possible to reproduce it using Netcat.

This was merged. Closing, thanks!