Skip to content
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

v11 and un-mocked nock request: socker hang up error #1226

Closed
2 tasks done
avaly opened this issue May 6, 2020 · 2 comments
Closed
2 tasks done

v11 and un-mocked nock request: socker hang up error #1226

avaly opened this issue May 6, 2020 · 2 comments

Comments

@avaly
Copy link

avaly commented May 6, 2020

Describe the bug

  • got version: 11.1.1
  • nock version: 12.0.3
  • Node.js version: 12.16.3
  • OS & version: Ubuntu 18.04.4

When got is used together with nock, but the request that got makes is not defined in nock (e.g. nock mocks a different path), an unexpected error is thrown: socket hang up.

This did not happen in got v10 with the same nock version.

Actual behavior

$ node got-bug-report.js 
events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: socket hang up
    at InterceptedRequestRouter.handleAbort (/home/dev/node_modules/nock/lib/intercepted_request_router.js:200:28)
    at OverriddenClientRequest.req.abort (/home/dev/node_modules/nock/lib/intercepted_request_router.js:79:35)
    at PromisableRequest._destroy (/home/dev/node_modules/got/dist/source/core/index.js:1026:32)
    at PromisableRequest.destroy (internal/streams/destroy.js:38:8)
    at PromisableRequest.<anonymous> (/home/dev/node_modules/got/dist/source/as-promise/index.js:188:25)
    at Object.onceWrapper (events.js:300:26)
    at PromisableRequest.emit (events.js:210:5)
    at PromisableRequest._beforeError (/home/dev/node_modules/got/dist/source/as-promise/core.js:113:14)
    at OverriddenClientRequest.<anonymous> (/home/dev/node_modules/got/dist/source/core/index.js:766:18)
    at Object.onceWrapper (events.js:300:26)
Emitted 'error' event on OverriddenClientRequest instance at:
    at /home/dev/node_modules/nock/lib/intercepted_request_router.js:108:11
    at processTicksAndRejections (internal/process/task_queues.js:75:11) {
  code: 'ECONNRESET'
}

Expected behavior

Using axios and nock the same sample code results in this error:

$ node got-bug-report.js 
Error Error: Nock: No match for request {
  "method": "GET",
  "url": "https://example.com/bar",
  "headers": {
    "accept": "application/json, text/plain, */*"
  }
}

Code to reproduce

// const axios = require('axios');
const got = require('got');
const nock = require('nock');

nock.disableNetConnect();

function run() {
  nock('https://example.com').get('/foo').reply(200);

  return got('https://example.com/bar');
  // return axios('https://example.com/bar');
}

run().catch(err => console.error('Error', err));

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

Duplicate of #1224

@szmarczak szmarczak marked this as a duplicate of #1224 May 6, 2020
@mastermatt
Copy link
Contributor

This is being track in Nock here: nock/nock#1992

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants