ninenines / gun

HTTP/1.1, HTTP/2, Websocket client (and more) for Erlang/OTP.
ISC License
891 stars 232 forks source link

Any way to get a connections' max_concurrent_streams ? #260

Closed igorclark closed 3 years ago

igorclark commented 3 years ago

Hi!

I can see the value is referred to in gun_http2.erl, but there's no apparent way in gun:info or the like to get it out. I know a client can get the info from the connection, because curl -v shows * Connection state changed (MAX_CONCURRENT_STREAMS == 128)! on a connection to a server I'm in control of, and changing http2_max_concurrent_streams on the nginx config is reflected in that banner.

I'd love to be able to access it so I can open a separate connection if i get to the limit in a current one. No idea how to go about adding this to cowboy though. Happy to have a go with some kind of pointer, unless it's really deep in there ...

Cheers 👍

ehamberg commented 3 years ago

@igorclark You can add #{notify_settings_changed => true} to http2_opts, you'll then get a {gun_notify, ConnPid, settings_changed, Settings} message when the connection is established (and again if the settings change). The Settings map contains a max_concurrent_streams key with an integer.

igorclark commented 3 years ago

Thanks @ehamberg, that'd be ideal! I'm getting {error,{options,{http2,{notify_settings_changed,true}}}}, is that likely because it's a 2.x feature and I'm on 1.3.3/stable?

essen commented 3 years ago

Yes it's 2.0+. Highly recommend upgrading, releasing 2.0 is just a matter of time and/or gathering feedback now.

igorclark commented 3 years ago

Ah great, thanks @essen, I'll give it a try. How far off would you say the 2.0 release is? Days, weeks maybe?

igorclark commented 3 years ago

Whoops, accidentally closed that. Unfortunately with 2.0.0-rc.1 and no other changes I get [error] gen_statem <0.624.0> in state connected terminated with reason: {{'function not exported',{cow_http2_machine,get_remote_settings,1}},state_functions}. The app is on cowboy 2.8.0, cowlib 2.9.1 (both automatically pulled in by rebar3 just by including cowboy in deps). I guess it might be upgrade issues in my code, but I don't really have time to track this down right now so I'll work with a fixed max_concurrent_streams for now and come back to this later. Cheers 👍

ehamberg commented 3 years ago

@igorclark I think you need cowlib ≥ 2.10.1 for cow_http2_machine:get_remote_settings/1.

igorclark commented 3 years ago

Ah, OK, I noticed the build was saying it was skipping cowlib 2.10.1 because it already had 2.9.1 - all pulled in automatically. I forced cowlib 2.10.1 in rebar.config and it worked. I guess this is something to do with the deps declaration in pre-2.0 release.

igorclark commented 3 years ago

@igorclark I think you need cowlib ≥ 2.10.1 for cow_http2_machine:get_remote_settings/1.

Thanks @ehamberg - crossed in the post!

essen commented 3 years ago

2.0 can be released after https://github.com/ninenines/gun/pull/257 is merged.

zuiderkwast commented 2 years ago

Please re-open this issue.

What should happen when the max number of streams is reached? Should gun queue the requests or should the application check the value and avoid sending more requests?

zuiderkwast commented 2 years ago

FYI: #280