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

dev server cannot be closed #18

Closed
qeleb opened this issue Jan 3, 2023 · 5 comments
Closed

dev server cannot be closed #18

qeleb opened this issue Jan 3, 2023 · 5 comments

Comments

@qeleb
Copy link

qeleb commented Jan 3, 2023

I am using a React SSR Fastify server with Vavite. When I close the dev server (for example, using Ctrl+C on macOS), the terminal window fails to close. When you try to close it with Ctrl+C, the dev server ceases to work, but continues to show text & does not return control to the user.

This is actually evident even in the Fastify Stackblitz example using the current version of Vite & Vavite.

Can you take a look at this?

@cyco130
Copy link
Owner

cyco130 commented Jan 4, 2023

Thanks for reporting. Maybe it's a macOS issue. I'll check on a mac and try to see what's going on.

@qeleb
Copy link
Author

qeleb commented Jan 4, 2023

it’s worth noting that it appears to work perfectly— the terminal closes with no issues— when I use Express instead of Fastify.

@ohmree
Copy link

ohmree commented Jan 8, 2023

Getting this with nestjs + fastify as well, created a project using @nestjs/cli then manually added vavite to it as shown in the nestjs example.

With the stock express-based setup everything worked as expected but when I tried using the fastify adapter I ran into the same issue - trying to terminate the dev server makes the process freeze and spikes its cpu usage.

Here's my main.ts, pretty standard (cobbled together from the nestjs and fastify examples and the official nestjs docs):

/// <reference types="vite/client" />

import { NestFactory } from '@nestjs/core';
import httpDevServer from 'vavite/http-dev-server';
import { AppModule } from './app.module';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import type { FastifyServerFactory, RawServerDefault } from 'fastify';
import type { AddressInfo } from 'node:net';

bootstrap();

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(
      import.meta.env.DEV
        ? {
            serverFactory: (handler => {
              // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
              httpDevServer!.on('request', handler);
              // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
              return httpDevServer!;
            }) as FastifyServerFactory<RawServerDefault>,
          }
        : undefined,
    ),
  );
  if (import.meta.env.PROD) {
    const port = process.env.PORT ?? 3000;
    app.listen(port);
  } else {
    try {
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
      await app.listen((httpDevServer!.address() as AddressInfo).port);
    } catch (e) {
      console.error(e);
      process.exit(1);
    }
  }
}

EDIT: after letting the server run for a couple of minutes and then trying to ctrl-c it I got this warning in the terminal, no idea if it's of any relevance:

(node:213762) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Server]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

@cyco130
Copy link
Owner

cyco130 commented Jan 14, 2023

I updated all examples to use handlerEntry instead of serverEntry.

serverEntry is unfortunately a hack. It happens to work under some circumstances but not always. I have a better way in mind to implement the same functionality in a much cleaner way if/when this PR lands on Vite.

Until then I'm unable to solve this, unfortunately. I'll keep it open as a reminder though :)

@cyco130 cyco130 closed this as completed May 23, 2023
@cyco130
Copy link
Owner

cyco130 commented May 23, 2023

This has been solved for sometime, alla examples are now working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants