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

TypeError: undefined is not an object (evaluating 'new tls.TLSSocket(new stream.PassThrough)._handle._parentWrap') #3061

Closed
Wftsrxy opened this issue May 25, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@Wftsrxy
Copy link

Wftsrxy commented May 25, 2023

What version of Bun is running?

0.6.4

What platform is your computer?

Linux 5.4.0-1106-azure x86_64 x86_64

What steps can reproduce the bug?

Use the got package and create a request with it.

import got from "got";
const google = await got('https://google.co.id/').text();

What is the expected behavior?

A succesful request.

What do you see instead?

TLSSocket._handle is undefined.

1 | 'use strict';
2 | const stream = require('stream');
3 | const tls = require('tls');
4 | 
5 | // Really awesome hack.
6 | const JSStreamSocket = (new tls.TLSSocket(new stream.PassThrough()))._handle._parentWrap.constructor;
                           ^
TypeError: undefined is not an object (evaluating 'new tls.TLSSocket(new stream.PassThrough)._handle._parentWrap')
      at /workspaces/codespaces-blank/node_modules/http2-wrapper/source/utils/js-stream-socket.js:6:24
      at /workspaces/codespaces-blank/node_modules/http2-wrapper/source/proxies/h1-over-h2.js:5:6
      at /workspaces/codespaces-blank/node_modules/http2-wrapper/source/index.js:12:1
      at /workspaces/codespaces-blank/node_modules/got/dist/source/core/options.js:11:0

Additional information

No response

@Wftsrxy Wftsrxy added the bug Something isn't working label May 25, 2023
@3ldar
Copy link

3ldar commented May 25, 2023

Darn too fast, I came here to open this issue :)

@3ldar
Copy link

3ldar commented Jun 27, 2023

While digging for the root cause of the error, I found this line in the deno source of TLSSocket they made a workaround to make this http2-wrapper library work. The library itself uses a hack to use the nodejs internal class named JSStreamSocket which is an internal optimization. This is the comment which explains what it does:

/* This class serves as a wrapper for when the C++ side of Node wants access
 * to a standard JS stream. For example, TLS or HTTP do not operate on network
 * resources conceptually, although that is the common case and what we are
 * optimizing for; in theory, they are completely composable and can work with
 * any stream resource they see.
 *
 * For the common case, i.e. a TLS socket wrapping around a net.Socket, we
 * can skip going through the JS layer and let TLS access the raw C++ handle
 * of a net.Socket. The flipside of this is that, to maintain composability,
 * we need a way to create "fake" net.Socket instances that call back into a
 * "real" JavaScript stream. JSStreamSocket is exactly this.
 */

Imho this might not be needed for bun as it seems pretty much node realm optimization. If it is needed it can be added in future. But now making this (new tls.TLSSocket(new stream.PassThrough()))._handle._parentWrap.constructor to return a Socket constructor would fix this error. Also, there is a duplicate issue here #3150 someone should merge them.

@slorber
Copy link

slorber commented Jun 29, 2023

Probably not super helpful, but maybe for someone using search will find it this way: had this error due to using npm package update-notifier

@stijnvanhulle
Copy link
Contributor

Probably related to this issue, in the 'http package both ClientRequest and OutgoingMessage are undefined causing the following error.

 6 | const {initializeTLSOptions } = require('./request-options');
 7 | const http = require('http');
 8 | const https = require('https');
 9 | const {Stream} = require('stream');
10 | function addFunctions(container , obj){
11 |   const proto = obj.prototype;
                    ^
TypeError: undefined is not an object (evaluating 'obj.prototype')
      at /Users/stijnvanhulle/GitHub/kubb/node_modules/.pnpm/http2-client@1.3.5/node_modules/http2-client/lib/request.js:11:16
      at /Users/stijnvanhulle/GitHub/kubb/node_modules/.pnpm/http2-client@1.3.5/node_modules/http2-client/lib/request.js:28:0
      at globalThis (/Users/stijnvanhulle/GitHub/kubb/node_modules/.pnpm/http2-client@1.3.5/node_modules/http2-client/lib/request.js:591:0)
      at /Users/stijnvanhulle/GitHub/kubb/node_modules/.pnpm/http2-client@1.3.5/node_modules/http2-client/lib/index.js:2:46
      at globalThis (/Users/stijnvanhulle/GitHub/kubb/node_modules/.pnpm/http2-client@1.3.5/node_modules/http2-client/lib/index.js:21:0)
console.log(http.ClientRequest, http, require('node:http'))

{
  Agent: [Function: Agent],
  Server: [Function: Server],
  METHODS: [ "ACL", "BIND", "CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LINK", "LOCK", "M-SEARCH", "MERGE",
    "MKACTIVITY", "MKCALENDAR", "MKCOL", "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH",
    "PURGE", "PUT", "REBIND", "REPORT", "SEARCH", "SOURCE", "SUBSCRIBE", "TRACE", "UNBIND", "UNLINK", "UNLOCK", "UNSUBSCRIBE"
  ],
  STATUS_CODES: {
    "100": "Continue",
    "101": "Switching Protocols",
    "102": "Processing",
    "103": "Early Hints",
    "200": "OK",
    "201": "Created",
    "202": "Accepted",
    "203": "Non-Authoritative Information",
    "204": "No Content",
    "205": "Reset Content",
    "206": "Partial Content",
    "207": "Multi-Status",
    "208": "Already Reported",
    "226": "IM Used",
    "300": "Multiple Choices",
    "301": "Moved Permanently",
    "302": "Found",
    "303": "See Other",
    "304": "Not Modified",
    "305": "Use Proxy",
    "307": "Temporary Redirect",
    "308": "Permanent Redirect",
    "400": "Bad Request",
    "401": "Unauthorized",
    "402": "Payment Required",
    "403": "Forbidden",
    "404": "Not Found",
    "405": "Method Not Allowed",
    "406": "Not Acceptable",
    "407": "Proxy Authentication Required",
    "408": "Request Timeout",
    "409": "Conflict",
    "410": "Gone",
    "411": "Length Required",
    "412": "Precondition Failed",
    "413": "Payload Too Large",
    "414": "URI Too Long",
    "415": "Unsupported Media Type",
    "416": "Range Not Satisfiable",
    "417": "Expectation Failed",
    "418": "I'm a Teapot",
    "421": "Misdirected Request",
    "422": "Unprocessable Entity",
    "423": "Locked",
    "424": "Failed Dependency",
    "425": "Too Early",
    "426": "Upgrade Required",
    "428": "Precondition Required",
    "429": "Too Many Requests",
    "431": "Request Header Fields Too Large",
    "451": "Unavailable For Legal Reasons",
    "500": "Internal Server Error",
    "501": "Not Implemented",
    "502": "Bad Gateway",
    "503": "Service Unavailable",
    "504": "Gateway Timeout",
    "505": "HTTP Version Not Supported",
    "506": "Variant Also Negotiates",
    "507": "Insufficient Storage",
    "508": "Loop Detected",
    "509": "Bandwidth Limit Exceeded",
    "510": "Not Extended",
    "511": "Network Authentication Required"
  },
  createServer: [Function: createServer],
  ServerResponse: [Function: ServerResponse],
  IncomingMessage: [Function: IncomingMessage],
  request: [Function: request],
  get: [Function: get],
  maxHeaderSize: 16384,
  setMaxIdleHTTPParsers: [Function: setMaxIdleHTTPParsers],
  globalAgent: [Getter],
  [Symbol(CommonJS)]: 0
}

@Entropy-10
Copy link

This also seems to be causing issues with Drizzle Kit. I have this error when using their push command from the cli. TypeError: undefined is not an object (evaluating 'secureSocket.ssl.verifyError') and this is the definition:

 const secureSocket = new Tls.TLSSocket(this.stream, {
  rejectUnauthorized,
  requestCert: true,
  secureContext,
  isServer: false
});

This is happening when using Windows 11 Ubuntu WSL 2024.2.33.0, Bun 1.0.2, and drizzle-kit 0.19.13.

@Electroid
Copy link
Contributor

The original issue was fixed, got now shows the following error instead.

215 |                 Object.assign(this.options.headers, source.headers);
216 |             }
217 |         });
218 |         this.on('newListener', event => {
219 |             if (event === 'retry' && this.listenerCount('retry') > 0) {
220 |                 throw new Error('A retry listener has been attached already.');
                          ^
error: A retry listener has been attached already.

This issue is being tracked here: #3150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants