req icon indicating copy to clipboard operation
req copied to clipboard

H2 release the stream reservation

Open powellnorma opened this issue 2 years ago • 3 comments

I read this comment:

https://github.com/imroc/req/blob/5323efe519c828b9b97dc52f13386e007e5972b5/internal/http2/client_conn_pool.go#L20-L22

But cc.RoundTrip(new(http.Request)) leads to a panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x58e3d4]

goroutine 18 [running]:
net/url.(*URL).String(0x0)
        /usr/local/go/src/net/url/url.go:810 +0x34
github.com/imroc/req/v3/internal/http2.(*ClientConn).RoundTrip(0xc00031a300, 0xc0003c8200)
       /req/internal/http2/transport.go:1162 +0x5

How can we release the stream reservation without doing a real RoundTrip?

powellnorma avatar Nov 29 '23 12:11 powellnorma

Is it enough to just call cc.decrStreamReservations()? Basically instead of doing a roundTrip here, I want to just return information about the TLS Connection - so I haven't called cc.RoundTrip yet, just acquired a connection via GetClientConn.

powellnorma avatar Nov 29 '23 19:11 powellnorma

It's just an internal implementation, which is based on golang.org/x/net/http2, you have no way to call it explicitly.

What specific scenarios would require controlling client connection reservation?

imroc avatar Nov 30 '23 02:11 imroc

Yes, I am already using an modified version of imroc/req, so this being internal functions/methods is no problem for me.

What specific scenarios would require controlling client connection reservation?

I have added an function PeekTLS to T1 and T2. Its usefull in an SSL MITM scenarios, where one wants to copy some characteristics of the original cert to the "faked" one (e.g. so that its expired when the original one is, etc).

Basically instead of calling roundTrip here, PeekTLS just returns information about the TLS Connection. But since cc.RoundTrip is not called, I want to unreserve it.

For T1 I just use t.tryPutIdleConn(pconn) - I think this is correct?

powellnorma avatar Nov 30 '23 10:11 powellnorma