denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.61k stars 5.25k forks source link

node: ClientRequest.options.createConnection #19507

Open monotter opened 1 year ago

monotter commented 1 year ago
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
bartlomieju commented 1 year ago

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.

RandyPen commented 1 year ago

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"]);
    },
  });
Mrowa96 commented 1 year ago

Same for me using puppeteer

import { join } from "https://deno.land/std@0.197.0/path/mod.ts";
import denoDir from "https://deno.land/x/dir/mod.ts";
import puppeteer from 'npm:puppeteer-core@21.0.2';
import {install, resolveBuildId} from "npm:@puppeteer/browsers@1.5.1"

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' });
acrodrig commented 1 year ago

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

theandym commented 11 months ago

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

uynilo9 commented 11 months ago

the same as me with npm:discord.js

SoftwareAndOutsourcing commented 11 months ago

I can reproduce this issue in #21096.

Abdillah commented 10 months ago

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)
}
kingkong404 commented 10 months ago

+1 having this issue with Discord JS

worotyns commented 9 months ago

Same in npm:@slack/bolt

mariusheil commented 9 months ago

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.

vanvanni commented 8 months ago

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

jpagand commented 8 months ago

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

gardc commented 5 months ago

+1 having this issue with Discord JS

Same here, still an issue.

ducan-ne commented 3 months ago

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

Sunf3r commented 3 months ago

Same in npm:baileys

maheshbansod commented 2 months ago

Issue still exists in 1.45.2

mariusheil commented 2 months ago

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.