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

Cannot unref() node http2 connections #16647

Closed
yzalium opened this issue Nov 15, 2022 · 12 comments · Fixed by #20712
Closed

Cannot unref() node http2 connections #16647

yzalium opened this issue Nov 15, 2022 · 12 comments · Fixed by #20712
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@yzalium
Copy link

yzalium commented Nov 15, 2022

Deno 1.28.0

While using npm compatibility, one of my dependencies establishes a http2 connection, and then tries to close the session calling session.unref(), which causes the following error

error: Uncaught TypeError: Cannot read properties of undefined (reading 'unref')
    at Subchannel.createSession (file:///Users/yzalium/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.7.3/build/src/subchannel.js:413:17)
    at file:///Users/yzalium/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.7.3/build/src/subchannel.js:502:18
    at Object.runMicrotasks (deno:core/01_core.js:377:30)
    at processTicksAndRejections (https://deno.land/[email protected]/node/_next_tick.ts:62:10)

This happens using the Cerbos package like so:

import { GRPC } from 'npm:@cerbos/grpc';

const client = new GRPC('localhost:3592', { tls: false })
const result = await client.checkResource({/* */})
client.close();
deno run --allow-env --allow-net --allow-write=. --allow-read=. main.ts

I've checked, and it doesn't seem like neither Cerbos nor its grpc dependency has postinstall scripts.

Thank you.

@dsherret dsherret added bug Something isn't working correctly node compat labels Nov 17, 2022
@spalberg
Copy link

spalberg commented Dec 12, 2022

Deno 1.28.3

I get the same exception when using zeebe-node which also establishes a grpc-connection.

Since we are in the process of deciding to use either Deno or NodeJS for script and CLI application development and we need such libraries, it would be good to know if GRPC should actually work with Deno via NPM packages and this is just a bug, or if Deno generally does not support GRPC via HTTP2 in NPM packages.

@c0per
Copy link

c0per commented Jan 2, 2023

Deno 1.29.1

Same exception using @grpc/grpc-js

@bartlomieju
Copy link
Member

@kt3k could you take a look at this issue?

@kt3k kt3k self-assigned this Jan 4, 2023
@cesumilo
Copy link

Little update on this issue. If you follow the quick-start guide here and setup the server using docker. Then, by running the code below:

import { GRPC } from 'npm:@cerbos/grpc';

const client = new GRPC('localhost:3593', { tls: false });
const kind = 'album:object';
const actions = ['view:public', 'comment'];

const cerbosPayload = {
  principal: {
    id: 'bugs_bunny',
    roles: ['user'],
    attributes: {
      beta_tester: true,
    },
  },
  resource: {
    kind: kind,
    id: 'BUGS001',
    attributes: {
      owner: 'bugs_bunny',
      public: false,
      flagged: false,
    },
  },
  actions: actions,
};
const decisions = await client.checkResource(cerbosPayload);
console.log(decisions);
client.close();

You get the following error:

deno run --allow-env --allow-net --allow-write=. --allow-read=. main.ts
// result: error: Uncaught NotOK: gRPC error 14 (UNAVAILABLE): No connection established

However, running the code below using ts-node works well.

import { GRPC } from '@cerbos/grpc';

(async () => {
  const client = new GRPC('localhost:3593', { tls: false });
  const kind = 'album:object';
  const actions = ['view:public', 'comment'];

  const cerbosPayload = {
    principal: {
      id: 'bugs_bunny',
      roles: ['user'],
      attributes: {
        beta_tester: true,
      },
    },
    resource: {
      kind: kind,
      id: 'BUGS001',
      attributes: {
        owner: 'bugs_bunny',
        public: false,
        flagged: false,
      },
    },
    actions: actions,
  };
  const decisions = await client.checkResource(cerbosPayload);
  console.log(decisions);
  client.close();
})();
ts-node main.ts
// result:
CheckResourcesResult {
  resource: { id: 'BUGS001', kind: 'album:object', policyVersion: '', scope: '' },
  actions: { comment: 'EFFECT_DENY', 'view:public': 'EFFECT_DENY' },
  validationErrors: [],
  metadata: undefined
}

I hope it helps! 🙏

@nubunto
Copy link

nubunto commented Apr 21, 2023

ran into this issue using Temporal SDK for TypeScript:

error: Uncaught TypeError: Cannot read properties of undefined (reading 'unref')
    at Subchannel.createSession (file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.7.3/build/src/subchannel.js:413:17)
    at file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.7.3/build/src/subchannel.js:502:18
    at eventLoopTick (ext:core/01_core.js:172:13)

Was able to reproduce with grpc-js as well:

✦ ❯ deno run grpcjs.ts
✅ Granted read access to "foo.proto".
error: Uncaught TypeError: Cannot read properties of undefined (reading 'setTimeout')
    at setupServer (file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.8.14/build/src/server.js:269:25)
    at file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.8.14/build/src/server.js:289:37
    at Array.map (<anonymous>)
    at bindSpecificPort (file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.8.14/build/src/server.js:277:44)
    at Object.onSuccessfulResolution (file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.8.14/build/src/server.js:419:45)
    at Timeout._onTimeout (file:///Users/nubunto/Library/Caches/deno/npm/registry.npmjs.org/@grpc/grpc-js/1.8.14/build/src/resolver-dns.js:128:31)
    at cb (ext:deno_node/internal/timers.mjs:37:46)
    at Object.action (ext:deno_web/02_timers.js:147:11)
    at handleTimerMacrotask (ext:deno_web/02_timers.js:64:10)
    at eventLoopTick (ext:core/01_core.js:171:21)

Seems like an issue when loading Node's http2 package?

@NfNitLoop
Copy link

Ran into this issue as well with Deno 1.35, when trying to use Google's SecretManagerService, which uses gRPC and so needs http/2 support:

Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.unref
Warning: Not implemented: Http2Session.ref
error: Uncaught TypeError: error sending request for url (http://secretmanager.googleapis.com:443/google.cloud.secretmanager.v1.SecretManagerService/GetSecret): connection error: Connection reset by peer (os error 54)
    at async mainFetch (ext:deno_fetch/26_fetch.js:266:12)
    at async fetch (ext:deno_fetch/26_fetch.js:490:7)
    at async node:http2:144:28

Steps to reproduce:

Unfortunately, you have to have valid gcloud credentials locally, else we fail before even making a connection:

  • install gcloud CLI
  • gcloud auth application-default login
import {SecretManagerServiceClient as Client} from "npm:@google-cloud/secret-manager"

const client = new Client({ projectId: "my-project"})
const secret = await client.getSecret({name: "my-secret"})

@oleggromov
Copy link

Having the same issue here as @NfNitLoop

@bartlomieju
Copy link
Member

I am currently working on improving support for node:http2 module specifically to support @google-cloud package.

@jotacamou
Copy link

jotacamou commented Aug 17, 2023

Just for the sake of reporting, I'm also experiencing the same issue with Deno v1.36.1 while trying to use the @google-cloud/secret-manager package.

@cesumilo
Copy link

cesumilo commented Sep 4, 2023

Same here, experiencing the issue with @google-cloud/pubsub, I hope it will be fixed soon 🙏

@bartlomieju bartlomieju assigned bartlomieju and unassigned kt3k Oct 1, 2023
bartlomieju added a commit that referenced this issue Oct 12, 2023
This commit improves "node:http2" module implementation, by enabling
to use "options.createConnection" callback when starting an HTTP2
session.
This change enables to pass basic client-side test with "grpc-js/grpc"
package.
Smaller fixes like "Http2Session.unref()" and "Http2Session.setTimeout()"
were handled as well.

Fixes #16647
bartlomieju added a commit that referenced this issue Oct 12, 2023
This commit improves "node:http2" module implementation, by enabling
to use "options.createConnection" callback when starting an HTTP2
session.
This change enables to pass basic client-side test with "grpc-js/grpc"
package.
Smaller fixes like "Http2Session.unref()" and "Http2Session.setTimeout()"
were handled as well.

Fixes #16647
@samrocksc
Copy link

Just checked this morning with 1.39:

  • Google Pub/Sub => same issue
  • Google Secret Manager => same issue

@mpcref
Copy link

mpcref commented Sep 15, 2024

Same issue here:

✗ deno -v
deno 2.0.0-rc.2

✗ deno run -A npm:trigger.dev@beta login

Trigger.dev (3.0.0-beta.56)

T  Logging in to Trigger.dev
|
o  Created authorization code
|
o  Please visit the following URL to login:
|  https://cloud.trigger.dev/account/authorization-code/Ws6oxuBRDovT7O0m4c1rzz_Gmb-6Zomzm7hGtqnYdQqkuFK3Lvsi62VLnamWi4bC
X Error: Cannot read properties of undefined (reading 'unref')

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

Successfully merging a pull request may close this issue.