denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.42k stars 5.37k 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 1 year ago

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

uynilo9 commented 1 year ago

the same as me with npm:discord.js

SoftwareAndOutsourcing commented 1 year ago

I can reproduce this issue in #21096.

Abdillah commented 11 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 11 months ago

+1 having this issue with Discord JS

worotyns commented 10 months ago

Same in npm:@slack/bolt

mariusheil commented 10 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 9 months ago

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

jpagand 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.

For me, the websocket reconnection logic doesn't work

gardc commented 6 months ago

+1 having this issue with Discord JS

Same here, still an issue.

ducan-ne commented 4 months ago

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

Sunf3r commented 4 months ago

Same in npm:baileys

maheshbansod commented 3 months ago

Issue still exists in 1.45.2

mariusheil commented 3 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.

elimydlarz commented 1 month ago

Also getting this error when trying to use OpenAI's new Realtime API client in my Deno project.

Broadly, it's problematic that Deno's WebSocket implementation is missing features from Node's implementation, mainly:

hydrangea-sh commented 1 month ago

The same issue is happening in with npm:shoukaku

xxhertz commented 4 weeks ago

socket.io-client causing the same issue

josephrocca commented 4 weeks ago

Another affected package: npm:chrome-remote-interface (DevTools debugger protocol)

mlshv commented 4 weeks ago

Same with npm:puppeteer

bartlomieju commented 3 weeks ago

Thanks for comments. We'll prioritize fixing this problem.

cobbvanth commented 3 weeks ago

Thanks for comments. We'll prioritize fixing this problem.

Awesome, thank you, just encountered this and am very excited for the merge.

RickDT commented 3 weeks ago

I think this is also blocking npm:wrangler pages dev which is Cloudflare's local preview environment.

TIA for prioritizing it!

herenickname commented 3 weeks ago

node:http agents are not working because of this, we are waiting! :)