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

fix: Cannot read property 'Symbol(TIMER::READ_TIMER)' of null #15

Merged
merged 1 commit into from
Jun 11, 2020

Conversation

nodejh
Copy link
Contributor

@nodejh nodejh commented Mar 26, 2020

当使用 SocksProxyAgent 做代理的时候,如果 new SocksProxyAgent('socks://127.0.0.1:3000') 中的 address 无法访问,则 httpx 内部会抛错,并且这个错误无法被正常捕获。

$ npm run test

> httpx@2.2.3 test /Users/jh/inbox/github/httpx
> mocha --reporter spec --timeout 3000 test/*.test.js



  httpx
(node:14882) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'Symbol(TIMER::READ_TIMER)' of null
    at ClientRequest.rejected (/Users/jh/inbox/github/httpx/lib/index.js:98:25)
    at ClientRequest.emit (events.js:196:13)
    at onerror (/Users/jh/inbox/github/httpx/node_modules/agent-base/dist/src/index.js:114:21)
    at callbackError (/Users/jh/inbox/github/httpx/node_modules/agent-base/dist/src/index.js:133:17)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:14882) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14882) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  it.only('should throw an error', async function () {
    try {
      // socks://127.0.0.1:3000 is an invalid socks proxy address.
      await make(server)('/', { agent: new SocksProxyAgent('socks://127.0.0.1:3000') });
      assert.fail('should not run here');
    } catch (error) {
      const port = server.address().port;
      assert.equal(error.message, `connect ECONNREFUSED 127.0.0.1:3000GET http://127.0.0.1:${port}/ failed.`);
    }
  });

@@ -95,7 +95,7 @@ exports.request = function (url, opts) {
var rejected = (err) => {
err.message += `${method} ${format(parsed)} failed.`;
// clear response timer when error
if (request.socket[READ_TIMER]) {
if (request.socket && request.socket[READ_TIMER]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当 socks 地址有误时,socket 就无法连接上,startResponseTimer 也就不会执行,所以这里 request.socket 也就是 null,所以需要判断一下。

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.621% when pulling 0600643 on nodejh:master into bcc8ddb on JacksonTian:master.

@JacksonTian JacksonTian merged commit 7f7861d into JacksonTian:master Jun 11, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants