snowflake-connector-nodejs icon indicating copy to clipboard operation
snowflake-connector-nodejs copied to clipboard

"got" package ability to make http(s)-requests is broken after the call snowflake.createConnection

Open t0lik opened this issue 3 years ago • 4 comments

  1. What version of NodeJS are you using (node --version and npm --version)? Nove version: v12.22.4 npm version: 6.14.11

  2. What operating system and processor architecture are you using?

Windows: Windows 10 Pro Version: 10.0.19044 build 19044

  1. What are the component versions in the environment (npm list)? got: 11.8.3 snowflake-sdk: 1.6.5 typescript: 4.4.2

  2. What did you do?

import snowflake, { Connection } from 'snowflake-sdk';
import got from 'got';

const conn = snowflake.createConnection({
            account: '',
            username: '',
            password: '',
            warehouse: '',
            database: '',
            schema: '',
            authenticator: 'SNOWFLAKE'
    });
const res = await got.get('https://www.google.com');
  1. What did you expect to see?

HTTP 200 response with HTML in a response body

  1. What did you see instead?

Error: "name": "RequestError", "code": "ECONNREFUSED", "message": connect ECONNREFUSED 127.0.0.1:443 stacktrace: RequestError: connect ECONNREFUSED 127.0.0.1:443 at ClientRequest. (<project_path>\node_modules\got\dist\source\core\index.js:962:111) at Object.onceWrapper (events.js:421:26) at ClientRequest.emit (events.js:326:22) at ClientRequest.EventEmitter.emit (domain.js:483:12) at ClientRequest.origin.emit (<project_path>\node_modules@szmarczak\http-timer\dist\source\index.js:43:20) at TLSSocket.socketErrorListener (_http_client.js:427:9) at TLSSocket.emit (events.js:314:20) at TLSSocket.EventEmitter.emit (domain.js:483:12) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:126:14)

  1. Add this to get standard output.
var snowflake = require('./snowflake');
snowflake.configure(
{
  logLevel: 'trace'
});

No trace messages in the console

t0lik avatar Nov 24 '21 13:11 t0lik

Please take into account this https://github.com/sindresorhus/got/issues/1572 and it seems you need to update https-proxy-agent package version from 3.0 to 5.0 in order to fix this bug

t0lik avatar Nov 25 '21 09:11 t0lik

You don't even need to call createConnection, just requiring the snowflake-sdk breaks it for me:

const got = require("got");
require("snowflake-sdk"); // if I comment-out this line then the code works fine

(async () => {
    const { statusCode } = await got.get("https://google.com");
    console.log(statusCode);
})();

TimShilov avatar Dec 06 '21 14:12 TimShilov

You don't even need to call createConnection, just requiring the snowflake-sdk breaks it for me:

For JS - yes, you're quite right. For TS - it's not that, after a compilation to JS it doesn't keep unused imports in JS-code.

t0lik avatar Dec 07 '21 17:12 t0lik

This breaks because the "agent-base" package is mutating a core nodejs BIF (https) and it does so in a way that is incompatible with how "got" does it's error handling.

I think it's probably a mistake/wrong that agent-base will mutate a core module function in this way, for a workaround back in the nodejs 9.0 days.

Let me link the relevant lines:

https://github.com/TooTallNate/node-agent-base/blob/4.3.0/patch-core.js#L11

The agent-base 4.3.0 looks quite a bit outdated, they're on 6.x which doesn't seem to have this patch in it.

ahungry avatar Feb 14 '22 19:02 ahungry

closing this issue as it seems to be resolved by #274 during the past year

sfc-gh-dszmolka avatar Jan 16 '23 15:01 sfc-gh-dszmolka