Skip to content

The problem of the program freezing and the timeout not working properly #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
NabiKAZ opened this issue Mar 4, 2025 · 2 comments
Open
Assignees
Labels
triage This ticket will be looked at shortly

Comments

@NabiKAZ
Copy link

NabiKAZ commented Mar 4, 2025

Description

I am sending requests every second. Look at the log below:

18:43:34.013 | [createSession]  Starting show month...
18:43:34.013 | [getUrl]         Fetching POST URL...
18:43:34.997 | [createSession]  Status: 200
18:43:35.018 | [createSession]  Entered!

18:43:35.019 | [checkOpen]      Starting Check open...
18:43:35.019 | [getUrl]         Fetching POST URL...
18:43:36.032 | [checkOpen]      Status: 200
18:43:36.052 | [checkOpen]      Entered!
18:43:36.053 | [checkOpen]      not found any item.

18:43:37.055 | [checkOpen]      Starting Check open...
18:43:37.055 | [getUrl]         Fetching POST URL...
18:45:25.020 | 

Everything is fine until suddenly the operation freezes! That is, where I expect to get the response and the status code to be displayed, nothing comes. It stays like this for hours, maybe forever.

I have set the timeout in the CycleTLS Request Config but it doesn't seem to have any effect.

On the other hand, in the library code I saw something like this:

export interface TimeoutOptions {
  /** How long should we wait on a request response before giving up */
  requestTimeout: number,
  /** How long should we wait before giving up on the request received handshake */
  acknowledgementTimeout?: number
}

While it is only used in this way and it seems to ignore that class and is not used anywhere:

timeout?: number;

I thought this might be relevant.

As a result, sometimes the program gets stuck in a way that timeout has no effect on it, and I have no choice but to periodically check and restart the app, and this is very annoying!

Issue Type

No response

Operating System

No response

Node Version

None

Golang Version

None

Relevant Log Output

@NabiKAZ NabiKAZ added the triage This ticket will be looked at shortly label Mar 4, 2025
@achernyi1988
Copy link

I have the same observation. Please, fix it

@NabiKAZ
Copy link
Author

NabiKAZ commented Mar 9, 2025

I wrote some code to manually handle timeout:

import initCycleTLS from 'cycletls';
const cycleTLS = await initCycleTLS();

const requestWithTimeout = async (url, options, method, timeout = 30000) => {
    let timeoutId;

    try {
        const timeoutPromise = new Promise((_, reject) => {
            timeoutId = setTimeout(() => {
                reject(new Error('Request timed out'));
            }, timeout);
        });

        const requestPromise = cycleTLS(url, options, method);
        
        return await Promise.race([requestPromise, timeoutPromise]);
    } catch (error) {
        throw error;
    } finally {
        if (timeoutId) clearTimeout(timeoutId);
    }
};

try {
    const response = await requestWithTimeout('https://httpbin.org/delay/7', { body: '', ja3: '', userAgent: '' }, 'get', 5000);
    console.log('response:', response);
} catch (error) {
    console.error('Error in request:', error.message);
} finally {
    cycleTLS.exit();
}

Or you can use the p-timeout library in a simpler way:

import pTimeout from 'p-timeout';
import initCycleTLS from 'cycletls';
const cycleTLS = await initCycleTLS();

try {
    const requestPromise = cycleTLS('https://httpbin.org/delay/6000', { body: '', ja3: '', userAgent: '' }, 'get');

    const response = await pTimeout(requestPromise, {
        milliseconds: 5000,
    });
    console.log('response:', response);
} catch (error) {
    console.error('Error in request:', error.message);
} finally {
    cycleTLS.exit();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage This ticket will be looked at shortly
Projects
None yet
Development

No branches or pull requests

3 participants