deno icon indicating copy to clipboard operation
deno copied to clipboard

node: ClientRequest.options.createConnection

Open monotter opened this issue 2 years ago • 27 comments

import tls from 'node:tls'
import https from 'node:https'
import net from 'node:net'

function tlsConnect(options) {
  options.path = undefined;

  if (!options.servername && options.servername !== '') {
    options.servername = net.isIP(options.host) ? '' : options.host;
  }

  return tls.connect(options);
}

const opts = {
  protocolVersion: 13,
  maxPayload: 104857600,
  skipUTF8Validation: false,
  perMessageDeflate: true,
  followRedirects: false,
  maxRedirects: 10,
  handshakeTimeout: 30000,
  createConnection: tlsConnect,
  socketPath: undefined,
  hostname: undefined,
  protocol: undefined,
  timeout: 30000,
  method: "GET",
  host: "gateway.discord.gg",
  path: "/?v=10&encoding=json",
  port: 443,
  defaultPort: 443,
  headers: {
    Connection: "Upgrade",
    Upgrade: "websocket",
    "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits"
  }
}

https.request(opts)

I've had an issue on DiscordJS with deno. Whenever I run this code I am getting this issue below. Ekran Resmi 2023-06-14 21 12 16

monotter avatar Jun 14 '23 18:06 monotter

FYI support for discord.js was added in https://github.com/denoland/deno/pull/19412 and will be released tomorrow in v1.34.3. That said ClientReuqest.options.createConnection is still not supported and ignored entirely.

bartlomieju avatar Jun 14 '23 22:06 bartlomieju

I encoutered a similar bug.

Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
Warning: Not implemented: ClientRequest.options.createConnection
error: Uncaught Error: Too many subscriptions on the connection
    at new JSONRPCError (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/@open-rpc/client-js/1.8.1/build/Error.js:24:28)
    at Object.exports.convertJSONToRPCError (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/@open-rpc/client-js/1.8.1/build/Error.js:37:16)
    at TransportRequestManager.processResult (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/@open-rpc/client-js/1.8.1/build/transports/TransportRequestManager.js:91:31)
    at TransportRequestManager.resolveRes (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/@open-rpc/client-js/1.8.1/build/transports/TransportRequestManager.js:113:18)
    at TransportRequestManager.resolveResponse (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/@open-rpc/client-js/1.8.1/build/transports/TransportRequestManager.js:53:25)
    at WebSocket.<anonymous> (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/@open-rpc/client-js/1.8.1/build/transports/WebSocketTransport.js:77:47)
    at WebSocket.onMessage (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/ws/7.5.9/lib/event-target.js:132:16)
    at WebSocket.emit (ext:deno_node/_events.mjs:379:28)
    at Receiver.receiverOnMessage (file:///Users/xxx/Library/Caches/deno/npm/registry.npmjs.org/ws/7.5.9/lib/websocket.js:1068:20)
    at Receiver.emit (ext:deno_node/_stream.mjs:1852:9)

the source code is

import { JsonRpcProvider, Connection, SuiEvent } from 'npm:@mysten/sui.js';

// Construct your connection:
const connection = new Connection({
	websocket: 'wss://fullnode.testnet.sui.io',
	faucet: 'https://faucet.testnet.sui.io/gas',
});
// connect to Testnet
const provider = new JsonRpcProvider(connection);

const promptPackage = '0x86e2ab6c370fbfed0ee955158ca95ca5b465dede4a79eb3594d2959e72d3d62a';
const promptFilter = { MoveModule: { package: promptPackage, module: 'cybrosnetwork' } };
const promptSub = await provider.subscribeEvent({
    filter: promptFilter,
    onMessage(event: SuiEvent) {
      // handle subscription notification message here
      console.log(event["parsedJson"]);
    },
  });

RandyPen avatar Jul 04 '23 10:07 RandyPen

Same for me using puppeteer

import { join } from "https://deno.land/[email protected]/path/mod.ts";
import denoDir from "https://deno.land/x/dir/mod.ts";
import puppeteer from 'npm:[email protected]';
import {install, resolveBuildId} from "npm:@puppeteer/[email protected]"

const {executablePath} = await install({
      browser: 'chrome',
      buildId: '113.0.5672.0',
      cacheDir: join(denoDir('cache'), "puppeteer")
});

const browser = await puppeteer.launch({
      headless: false,
      executablePath, 
});

const page = await browser.newPage();

await page.setContent(`<p>test</p>`, { waitUntil: 'networkidle2' });

Mrowa96 avatar Aug 10 '23 10:08 Mrowa96

Is there a workaround? I am trying to use Deno with the mqtt and I get the same issue. Thanks.

acrodrig avatar Oct 03 '23 17:10 acrodrig

I'm also experiencing this issue with CCXT — specifically with CCXT Pro and its connection via websockets for the watch* methods.

theandym avatar Oct 16 '23 04:10 theandym

the same as me with npm:discord.js

uynilo9 avatar Oct 28 '23 03:10 uynilo9

I can reproduce this issue in #21096.

SoftwareAndOutsourcing avatar Nov 06 '23 11:11 SoftwareAndOutsourcing

I'm reproducing this on npm:selenium-webdriver which uses Chrome Debug Protocol (using websocket, ws package). Using the following code:

import { Builder } from 'npm:selenium-webdriver';

const builder = new Builder()
.forBrowser(Browser.CHROME)

try {
    const driver = await builder.build();
    const cdp = await driver.createCDPConnection('page');
} catch(e) {
    console.log("ERR", e)
}

Abdillah avatar Dec 01 '23 11:12 Abdillah

+1 having this issue with Discord JS

kingkong404 avatar Dec 04 '23 14:12 kingkong404

Same in npm:@slack/bolt

worotyns avatar Jan 02 '24 14:01 worotyns

I am also using mqtt.js and while everything seems to work, the same error is thrown and it would be nice if it were fixed. Not sure of the implications when this error is thrown.

mariusheil avatar Jan 07 '24 10:01 mariusheil

+1, Also encountering this in Discord.JS and still have to start with MQTT.

vanvanni avatar Jan 17 '24 17:01 vanvanni

I am also using mqtt.js and while everything seems to work, the same error is thrown and it would be nice if it were fixed. Not sure of the implications when this error is thrown.

For me, the websocket reconnection logic doesn't work

jpagand avatar Jan 23 '24 10:01 jpagand

+1 having this issue with Discord JS

Same here, still an issue.

gardc avatar May 01 '24 03:05 gardc

Same here, this blocks me from using port checking libs, wondering any workaround for that

ducan-ne avatar Jun 18 '24 12:06 ducan-ne

Same in npm:baileys

Sunf3r avatar Jun 27 '24 00:06 Sunf3r

Issue still exists in 1.45.2

maheshbansod avatar Jul 16 '24 05:07 maheshbansod

For npm:mqtt, this is really annoying as it is the only major mqtt implementation that can be used for deno. All the other implementations are not maintained anymore. At least I was not able to find a maintained package.

mariusheil avatar Jul 16 '24 06:07 mariusheil