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: expected i32 #27091

Open
joeldomke opened this issue Nov 26, 2024 · 6 comments · May be fixed by #27931
Open

TypeError: expected i32 #27091

joeldomke opened this issue Nov 26, 2024 · 6 comments · May be fixed by #27931
Labels
bug Something isn't working correctly ext/http related to ext/http node compat node:http Issues with `node:http` module - to be fixed with a rewrite

Comments

@joeldomke
Copy link

joeldomke commented Nov 26, 2024

Version: Deno 2.1.1

I wrote an LTI integration using ltijs as an node app. Then I tried to move the code into an edge function and it fails with the following error:

runtime has escaped from the event loop unexpectedly: event loop error: TypeError: expected i32
    at IncomingMessageForClient._read (node:http:781:10)
    at Readable.read (ext:deno_node/_stream.mjs:2995:16)
    at resume_ (ext:deno_node/_stream.mjs:3345:16)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:33:15)
    at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
    at eventLoopTick (ext:core/01_core.js:175:21)
failed to send request to user worker: event loop error: TypeError: expected i32
    at IncomingMessageForClient._read (node:http:781:10)
    at Readable.read (ext:deno_node/_stream.mjs:2995:16)
    at resume_ (ext:deno_node/_stream.mjs:3345:16)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:33:15)
    at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
    at eventLoopTick (ext:core/01_core.js:175:21)
user worker failed to respond: event loop error: TypeError: expected i32
    at IncomingMessageForClient._read (node:http:781:10)
    at Readable.read (ext:deno_node/_stream.mjs:2995:16)
    at resume_ (ext:deno_node/_stream.mjs:3345:16)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:33:15)
    at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
    at eventLoopTick (ext:core/01_core.js:175:21)
InvalidWorkerResponse: event loop error: TypeError: expected i32
    at IncomingMessageForClient._read (node:http:781:10)
    at Readable.read (ext:deno_node/_stream.mjs:2995:16)
    at resume_ (ext:deno_node/_stream.mjs:3345:16)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:33:15)
    at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
    at eventLoopTick (ext:core/01_core.js:175:21)
    at async Promise.allSettled (index 1)
    at async UserWorker.fetch (ext:sb_user_workers/user_workers.js:72:61)
    at async Object.handler (file:///root/index.ts:173:14)
    at async respond (ext:sb_core_main_js/js/http.js:163:14) {
  name: "InvalidWorkerResponse"
}

While working with the node app I was able to modify the ltijs code in the node_modules to pinpoint any issues. This is no longer possible since I moved everything into Supabase edge functions.

The library uses the node module debug for logging. But when I try to turn on logging using an environment variable I get a completely new error.

runtime has escaped from the event loop unexpectedly: event loop error: NotSupported: The operation is not supported
    at Object.setEnv [as set] (ext:sb_env/env.js:5:9)
    at Object.set (ext:deno_node/_process/process.ts:66:14)
    at Function.save (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/debug/4.3.7/src/node.js:205:21)
    at Function.enable (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/debug/4.3.7/src/common.js:163:15)
    at file:///Users/joel/IdeaProjects/business-simulation/supabase/functions/ltijs/index.ts:6:7

Does this mean that certain node features required by this library are not yet supported by Deno?

Without logging or being able to modify the ltijs library I am unsure how to further narrow down the problem.

Here is my code:

import { Provider as lti } from 'ltijs';
import Database from './DB.ts';
import pg from 'pg';

// Setup ltijs-sequelize using the same arguments as Sequelize's generic contructor
// Database is hosted under http://localhost:54322/
const db = new Database('postgres', 'postgres', 'postgres', {
    host: '172.17.0.1',
    port: 54322,
    dialect: 'postgres',
    schema: 'lti',
    dialectModule: pg,
    logging: true,
});

// Setup provider
lti.setup(
    'LTIKEY', // Key used to sign cookies and tokens
    {
        plugin: db,
    },
    {
        // Options
        appRoute: '/ltijs/launch',
        loginRoute: '/ltijs/login', // Optionally, specify some of the reserved routes
        cookies: {
            secure: false, // Set secure to true if the testing platform is in a different domain and https is being used
            sameSite: '', // Set sameSite to 'None' if the testing platform is in a different domain and https is being used
        },
        devMode: true, // Set DevMode to false if running in a production environment with https
    },
);

// Set lti launch callback
lti.onConnect((token, req, res) => {
    console.log('onConnect');
    console.log(token);
    return res.send("It's alive!");
});

const setup = async () => {
    // Deploy server and open connection to the database
    await lti.deploy({ port: 3000 }); // Specifying port. Defaults to 3000

    // Register platform
    await lti.registerPlatform({
        url: 'https://saltire.lti.app/platform',
        name: 'Saltire LTI App',
        clientId: 'saltire.lti.app',
        authenticationEndpoint: 'https://saltire.lti.app/platform/auth',
        accesstokenEndpoint: 'https://saltire.lti.app/platform/token/30d3313d7c655cdc2e722bafeb7374b9',
        authConfig: {
            method: 'JWK_SET',
            key: 'https://saltire.lti.app/platform/jwks/30d3313d7c655cdc2e722bafeb7374b9',
        },
    });
};

setup();
@joeldomke
Copy link
Author

joeldomke commented Nov 26, 2024

First, the login route is called without any issues. This shows the library is somewhat working and the database connection is also working. The second request is to the app route.

There is a session validator used by the express server that is skipped for the login route. I guess that is where the call to the app route is failing but this method has more than 250 lines of code and also depends on other libraries as far as I can tell.

I understand that you can't debug that code. If the stack trace is not enough to point toward an issue I would be grateful for any hints on how to narrow this problem down.

@joeldomke
Copy link
Author

joeldomke commented Nov 26, 2024

Okay, I just noticed that I have Deno 2.1.1 installed. But since I am using the Supabase Edgeruntime it is an older version:

Using supabase-edge-runtime-1.62.2 (compatible with Deno v1.45.2)

@joeldomke
Copy link
Author

Switching from 'npm:ltijstohttps://esm.sh/[email protected]` produces

Download https://esm.sh/error.js?type=unsupported-node-builtin-module&name=http2&[email protected]
Download https://esm.sh/error.js?type=unsupported-node-builtin-module&name=async_hooks&[email protected]
Download https://esm.sh/error.js?type=unsupported-node-builtin-module&name=async_hooks&[email protected]
worker boot error: failed to create the graph: Import 'https://esm.sh/error.js?type=unsupported-node-builtin-module&name=http2&[email protected]' failed: 500 Internal Server Error
    at https://esm.sh/v135/[email protected]/esnext/http2-wrapper.mjs:4:23
worker boot error: failed to create the graph: Import 'https://esm.sh/error.js?type=unsupported-node-builtin-module&name=http2&[email protected]' failed: 500 Internal Server Error
    at https://esm.sh/v135/[email protected]/esnext/http2-wrapper.mjs:4:23
InvalidWorkerCreation: worker boot error: failed to create the graph: Import 'https://esm.sh/error.js?type=unsupported-node-builtin-module&name=http2&[email protected]' failed: 500 Internal Server Error
    at https://esm.sh/v135/[email protected]/esnext/http2-wrapper.mjs:4:23
    at async UserWorker.create (ext:sb_user_workers/user_workers.js:139:15)
    at async Object.handler (file:///root/index.ts:156:22)
    at async respond (ext:sb_core_main_js/js/http.js:163:14) {
  name: "InvalidWorkerCreation"
}

So I guess something around http2 is just not supported by the Deno version I use.

@marvinhagemeister
Copy link
Contributor

The http and http2 module received lots of bug fixes leading up to Deno 2.x . Does the error occur in latest Deno version too or only in older ones?

@joeldomke
Copy link
Author

I ran the index.ts using Deno 2.1.1 instead of the Supabase Edge Functions and the error still occurs. However, I managed to narrow down the problem. This is a minimal reproducible that works in Node but not in Deno:

import { got } from 'npm:got';

got.get('https://saltire.lti.app/platform/jwks/30d3313d7c655cdc2e722bafeb7374b9');

results in:

Uncaught (in promise) RequestError: no upgrade available
    at HttpsClientRequest.<anonymous> (file:///Users/joel/IdeaProjects/business-simulation/supabase/functions/ltijs/node_modules/.deno/[email protected]/node_modules/got/dist/source/core/index.js:673:107)
    at Object.onceWrapper (ext:deno_node/_events.mjs:518:26)
    at HttpsClientRequest.emit (ext:deno_node/_events.mjs:405:35)
    at node:http:396:16
    at eventLoopTick (ext:core/01_core.js:175:7)
Caused by: Http: no upgrade available
    at node:http:352:36
    at eventLoopTick (ext:core/01_core.js:175:7)

Note that got.get('https://google.com'); works.

deno --version
deno 2.1.1 (stable, release, aarch64-apple-darwin)
v8 13.0.245.12-rusty
typescript 5.6.2

@joeldomke
Copy link
Author

And if I await the get request I get the same error as before:

import { got } from 'npm:got';

await got.get('https://saltire.lti.app/platform/jwks/30d3313d7c655cdc2e722bafeb7374b9');
Uncaught (in promise) TypeError: expected i32
    at IncomingMessageForClient._read (node:http:682:10)
    at IncomingMessageForClient.Readable.read (ext:deno_node/_stream.mjs:2561:16)
    at resume_ (ext:deno_node/_stream.mjs:2911:16)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:36:15)
    at runNextTicks (ext:deno_node/_next_tick.ts:76:3)
    at eventLoopTick (ext:core/01_core.js:182:21)

@lucacasonato lucacasonato added bug Something isn't working correctly node compat ext/http related to ext/http node:http Issues with `node:http` module - to be fixed with a rewrite labels Nov 27, 2024
@littledivy littledivy linked a pull request Feb 2, 2025 that will close this issue
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 ext/http related to ext/http node compat node:http Issues with `node:http` module - to be fixed with a rewrite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants