Skip to content

Server.respond() launches setInterval into event loop while running on nodejs runtime #10005

@falmar

Description

@falmar

Describe the bug

(I may be doing something wrong yet dont know) im new to svelte 🤣 trying to run it on lambda aws...

Just as the title states,

i have added config.kit.version.pollInterval setting in svelte.config.js,

In a attempt to create custom adapter for AWS Lambda, i'm directly the calling a javascript file with nodejs that would very roughly simulate a lambda request call, then i noticed that the process would hang for a minute before exiting, removing the .pollInterval setting stopped this from happening.

I aws expecting this to not run on nodejs runtime but client only.

svelte.config.js import the adapter (based on adapter-node build process) includes the shims installPolyfills,

import adapter from './adapter-lambda/index.js';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
		version: {
			pollInterval: 60 * 1000
		},

		adapter: adapter({
			out: 'build',
			precompress: true,
			polyfill: true
		})
	}
};

export default config;

and the adapter code is basically just this, setting Server option prerendering.fallback = true seems to solve the problem but then i dont receive any SSR content

const req = new Request(url.toString(), {
	method: method,
	headers: headers,
	body: null
});

const server = new Server(manifest);
await server.init({ env });

return await server.respond(req, {
	platform: { req },
	// it hangs without this
	prerendering: {
	    fallback: true
	}
});

this is the js file that calls and attempts to use the adapter, it calls the /about url which is set prerender = false so it gives some output

import svelte from './build/svelte.js';

async function run() {
	const origin = process.env.ORIGIN || 'http://localhost:3000';

	const response = await svelte({
		env: process.env,
		url: new URL(origin + '/about'),
		method: 'GET',
		headers: new Headers({
			'accept-encoding': 'gzip, deflate, br',
			'accept-language': 'en-US,en;q=0.9',
			host: 'localhost:3000'
		}),
		body: null
	});

	console.log('Body:', await response.text());
	console.log('Headers:', response.headers);
	console.log('Status:', response.status);
}

run();

Reproduction

Repo: [email protected]:falmar/svelte-kit-version-poll-issue.git

To reproduce the issue,

  • simply install the repo and dependencies and build the package
$ npm install
$ npm build
  • call the lambda.js at the root project directory, which should hang for a minute after giving the output
$ node lambda.js
  • then toggle on/off the config.kit.version.pollInterval setting.

Is something that I wouldn't notice at all if wasn't trying to run it on a single execution unlike a node server which is continuously running...

Logs

No response

System Info

System:
    OS: Linux 6.2 Fedora Linux 37 (Workstation Edition)
    CPU: (16) x64 AMD Ryzen 7 5800X3D 8-Core Processor
    Memory: 20.60 GB / 31.24 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.7.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.15.0 - /usr/bin/npm
  Browsers:
    Chrome: 113.0.5672.92
    Firefox: 112.0.2
  npmPackages:
    @sveltejs/adapter-auto: ^2.1.0 => 2.1.0 
    @sveltejs/adapter-node: ^1.2.4 => 1.2.4 
    @sveltejs/kit: ^1.18.0 => 1.18.0 
    svelte: ^3.59.1 => 3.59.1 
    vite: ^4.3.8 => 4.3.8

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions