Page MenuHomePhabricator

preq emits unhandled rejection on socket timeout
Open, MediumPublic


When running RESTBase tests there's quite a few unhandled rejection logs. There rejections are generated in preq and are not being caught for some reason.

Attempts to reproduce with a smaller tests failed, for example

process.on('unhandledRejection', e => console.log('aaaaa', e));
const nock = require('nock');
nock('http://localhost:8085').get('/a').times(2).delay(5000).reply(200, 'a');
return request({
    uri: 'http://localhost:8085/a',
    method: 'get',
    maxAttempts: 2,
    timeout: 1000,
    promiseFactory: resolver => new P(resolver),
    agentClass: createConnectTimeoutAgent('http'),
    agentOptions: defaultAgentOptions,
    retryStrategy: (err, response) => {
        if (response && response.statusCode === 503
            && /^[0-9]+$/.test(response.headers['retry-after'])) {
            this.delay = parseInt(response.headers['retry-after'], 10) * 1000;
            return true;
        return request.RetryStrategies.HTTPOrNetworkError(err, response);
.then((res) => console.log('HERE', res), (err) => console.log('THERE', err));

(run from 'preq/index.html')

Successfully catches the socket timeout. We need to figure out why the unhandled rejections happen.

What to do:

  • Instrument preq with more logging to figure out where do unhandled rejections come from while RESTBase tests are running
  • Create a reproducible testcase to demonstrate the problem
  • Fix the problem and convert a test case to a unit test

Acceptance criteria:

  • Running RESTBase tests doesn't log unhandled rejections due to socket timeouts in preq.

Event Timeline

Pchelolo created this task.Mar 27 2019, 5:21 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 27 2019, 5:21 PM
mobrovac renamed this task from press emits unhandled rejection on socket timeout to preq emits unhandled rejection on socket timeout.Mar 27 2019, 10:47 PM
Pchelolo triaged this task as Medium priority.May 16 2019, 9:22 AM
Pchelolo updated the task description. (Show Details)