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

fix: abnormal port occupation #4489

Open
wants to merge 1 commit into
base: release-4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/bootstrap/cli/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const webpackExtensionConfig = require('../webpack/webpack.extension.conf');
const path = require('path');
const fs = require('fs-extra');
const npmCheck = require('npm-checky');
const chalk = require('chalk');
const interactiveUpdate = require('npm-checky/lib/out/interactive-update');

const resolve = dir => path.resolve(process.cwd(), dir);
Expand Down Expand Up @@ -75,7 +76,10 @@ async function devServer(setAlias, checkUpgrade) {
const server = new wds(devServerOptions, compiler);

server.startCallback(() => {
console.log('Successfully started server on http://localhost:8000');
console.log(
chalk.green.bold('Successfully started server on ') +
chalk.blue.bold.underline('http://localhost:8000'),
);
});
}

Expand Down
34 changes: 33 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const Koa = require('koa');
const path = require('path');
const chalk = require('chalk');

Koa.prototype.apply = function (module, ...rest) {
module(this, ...rest);
Expand Down Expand Up @@ -39,7 +40,38 @@ app.server = app.listen(global.PORT, err => {
return console.error(err);
}
/* eslint-disable no-console */
console.log(`Dashboard app running at port ${global.PORT}`);
console.log(chalk.green.bold(`Dashboard app running at port ${global.PORT}`));
});

app.apply(wsProxy);

const shutdown = () => {
console.log('Received shutdown signal. Starting graceful shutdown...');

// waiting for the server to shut down
app.server.close(err => {
if (err) {
console.error('Error during server shutdown:', err);
process.exit(1);
}
console.log('Server closed successfully.');
process.exit(0);
});

// If shutdown times out, force quit
setTimeout(() => {
console.log('Force quitting due to shutdown timeout.');
process.exit(1);
}, 5000);
};

// Capture Ctrl+C
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a condition to take effect only in the development environment

process.on('SIGINT', () => {
console.log('\nSIGINT signal received.');
shutdown();
});
// Capturing the termination signal
process.on('SIGTERM', () => {
console.log('SIGTERM signal received.');
shutdown();
});