Skip to content

Fix crash when WINDOW_UPDATE follows GOAWAY with buffered stream data#365

Open
manas-chaudhari wants to merge 1 commit intoninenines:masterfrom
manas-chaudhari:fix-goaway-window-update-crash
Open

Fix crash when WINDOW_UPDATE follows GOAWAY with buffered stream data#365
manas-chaudhari wants to merge 1 commit intoninenines:masterfrom
manas-chaudhari:fix-goaway-window-update-crash

Conversation

@manas-chaudhari
Copy link
Copy Markdown

@manas-chaudhari manas-chaudhari commented Apr 8, 2026

When a GOAWAY frame removes streams from gun's map but does not inform cow_http2_machine, a subsequent WINDOW_UPDATE triggers send_data in the machine which finds buffered data for the removed stream and returns it, causing gun_http2 to look up the stream in its now-smaller map and crash with {badkey, StreamID}.

This happens regardless of whether the frames arrive in the same or separate TCP segments.

Fix: call cow_http2_machine:reset_stream/2 for each stream removed by the GOAWAY handler so the machine no longer holds buffered data for those streams.

Test failure before fix

** Reason for termination = error:{badkey,5}
** Callback modules = [gun]
** Callback mode = state_functions
** Stacktrace =
**  [{erlang,map_get,[5,#{}],[{error_info,#{module => erl_erts_errors}}]},
     {gun_http2,get_stream_by_id,2,[{file,"src/gun_http2.erl"},{line,1668}]},
     {gun_http2,send_data,6,[{file,"src/gun_http2.erl"},{line,1294}]},
     {gun_http2,send_data,4,[{file,"src/gun_http2.erl"},{line,1280}]},
     {gun_http2,frame,5,[{file,"src/gun_http2.erl"},{line,359}]},
     {gun_http2,parse,5,[{file,"src/gun_http2.erl"},{line,260}]},
     {gun,handle_common_connected_no_input,4,
          [{file,"src/gun.erl"},{line,1587}]},
     {gen_statem,loop_state_callback,11,
                 [{file,"gen_statem.erl"},{line,1395}]}]

When a GOAWAY frame removes streams from gun's map but does not inform
cow_http2_machine, a subsequent WINDOW_UPDATE triggers send_data in the
machine which finds buffered data for the removed stream and returns it,
causing gun_http2 to look up the stream in its now-smaller map and crash
with {badkey, StreamID}.

This happens regardless of whether the frames arrive in the same or
separate TCP segments.

Fix: call cow_http2_machine:reset_stream/2 for each stream removed
by the GOAWAY handler so the machine no longer holds buffered data
for those streams.
@manas-chaudhari manas-chaudhari force-pushed the fix-goaway-window-update-crash branch from 7ae61b6 to 2a61d0b Compare April 8, 2026 22:10
@manas-chaudhari manas-chaudhari changed the title Fix crash when GOAWAY and WINDOW_UPDATE arrive in same TCP segment Fix crash when WINDOW_UPDATE follows GOAWAY with buffered stream data Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant