bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
670 stars 133 forks source link

[Bug]: Timeout Broken / Stream does not end when using StreamOutputPath option #62

Open Jamucy opened 11 months ago

Jamucy commented 11 months ago

TLS client version

v1.4.0

System information

tls-client-windows-64.dll

Issue description

When set StreamOutputPath Option timeoutSeconds or WithTimeoutMilliseconds do not work correctly

the stream connection does not end after the set timeout and causing a lock

without StreamOutputPath i am able to stream and timeout is working fine/closing connection at timeout

Steps to reproduce / Code Sample

set StreamOutputPath

bogdanfinn commented 11 months ago

@Jamucy i'm currently trying to debug and reproduce this issue... do you maybe have some example code / payload to reproduce this?

The Timeout option only affects the request itself. Streaming the response into a file with the StreamOutputPath only happens after the request is fully done (either timeouted or did not timeout).

I think there is another reason why the file is locked... but i need some code to reproduce this isse..

FYI:


    resp, reqErr := tlsClient.Do(req)

    if reqErr != nil {
        clientErr := tls_client_cffi_src.NewTLSClientError(fmt.Errorf("failed to do request: %w", reqErr))

        return handleErrorResponse(sessionId, withSession, clientErr)
    }

    if resp == nil {
        clientErr := tls_client_cffi_src.NewTLSClientError(fmt.Errorf("response is nil"))

        return handleErrorResponse(sessionId, withSession, clientErr)
    }

    targetCookies := tlsClient.GetCookies(resp.Request.URL)

// at this point the request is fully done already and we are just streaming the response into a file if the option is set. No timeout should affect this anymore.
    response, err := tls_client_cffi_src.BuildResponse(sessionId, withSession, resp, targetCookies, requestInput)
    if err != nil {
        return handleErrorResponse(sessionId, withSession, err)
    }