nodejs/node

https.request timeout options doesn't work

Open

#23.282 geöffnet am 5. Okt. 2018

Auf GitHub ansehen
 (10 Kommentare) (4 Reaktionen) (0 zugewiesene Personen)JavaScript (35.535 Forks)batch import
help wantedhttpsstale

Repository-Metriken

Stars
 (117.218 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 18T 17h) (219 gemergte PRs in 30 T)

Beschreibung

Node version 8.11.3. 64-bit Windows 8.1

As I understood from docs, timeout property in https.request options sets socket connection timeout. I set it to minimum - 1 millisecond and it should definitely trigger 'timeout' event.

    const options = {
        host: 'yobit.net',
        path: '/api/3/depth/ltc_btc',
        timeout: 1
    }
    const req = https.request(options, res => {
    });
    
    req.on('timeout', () => {
        console.error('request timeout');
    })
    req.end();

I expect 'reqest timeout' console message but it doen't appear.

However, when I create my custom https Agent with overriden createConnection method that sets initial socket timeout to 1 millisecond there:

MyAgent.prototype.createConnection = function() {
    const socket = https.Agent.prototype.createConnection.apply(this, arguments);
    socket.setTimeout(1);
    return socket;
}

and run the first code with agent parameter set to my custom agent, now it fires 'timeout' event.

Contributor Guide