-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Error:Kill child process will case "kill ESRCH" when "Error in connection establishment: net::ERR_CONNECTION_REFUSED" #8534
Comments
@zhaomenghuan I believe you may have encountered the following issue: #4249 |
I have noticed this issue several times already; for some reason, the backed process just terminates. When closing the electron app, we try to close the forked BE process, but it's not there anymore. This issue requires two fixes:
|
Is there any better solution to handle the failed "Error in connection establishment: net:ERR_CONNECTION_REFUSED" exception? When is the official plan to fix this problem? The application experience of this problem in the Electron environment is very affected. |
For the record, this 👆 exception is causing the As for the
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(YourElectronMainApplication).toSelf().inSingletonScope();
rebind(ElectronMainApplication).toService(ElectronMainApplication);
});
@injectable()
export class YournElectronMainApplication extends ElectronMainApplication {
protected async startBackend(): Promise<number> {
// Check if we should run everything as one process.
const noBackendFork = process.argv.indexOf('--no-cluster') !== -1;
// We cannot use the `process.cwd()` as the application project path (the location of the `package.json` in other words)
// in a bundled electron application because it depends on the way we start it. For instance, on OS X, these are a differences:
// https://github.com/eclipse-theia/theia/issues/3297#issuecomment-439172274
process.env.THEIA_APP_PROJECT_PATH = this.globals.THEIA_APP_PROJECT_PATH;
// Set the electron version for both the dev and the production mode. (https://github.com/eclipse-theia/theia/issues/3254)
// Otherwise, the forked backend processes will not know that they're serving the electron frontend.
process.env.THEIA_ELECTRON_VERSION = process.versions.electron;
if (noBackendFork) {
process.env[ElectronSecurityToken] = JSON.stringify(this.electronSecurityToken);
// The backend server main file is supposed to export a promise resolving with the port used by the http(s) server.
const address: AddressInfo = await require(this.globals.THEIA_BACKEND_MAIN_PATH);
return address.port;
} else {
let args = this.processArgv.getProcessArgvWithoutBin();
// https://github.com/eclipse-theia/theia/issues/8227
if (process.platform === 'darwin') {
// https://github.com/electron/electron/issues/3657
// https://stackoverflow.com/questions/10242115/os-x-strange-psn-command-line-parameter-when-launched-from-finder#comment102377986_10242200
// macOS appends an extra `-psn_0_someNumber` arg if a file is opened from Finder after downloading from the Internet.
// "AppName" is an app downloaded from the Internet. Are you sure you want to open it?
args = args.filter(arg => !arg.startsWith('-psn'));
}
const backendProcess = fork(
this.globals.THEIA_BACKEND_MAIN_PATH,
args,
await this.getForkOptions(),
);
return new Promise((resolve, reject) => {
// The backend server main file is also supposed to send the resolved http(s) server port via IPC.
backendProcess.on('message', (address: AddressInfo) => {
resolve(address.port);
});
backendProcess.on('error', error => {
reject(error);
});
app.on('quit', () => {
try {
// If we forked the process for the clusters, we need to manually terminate it.
// See: https://github.com/eclipse-theia/theia/issues/835
process.kill(backendProcess.pid);
} catch (e) {
if (e.code === 'ESRCH') {
console.log('Could not terminate the backend process. It was not running.');
return;
}
throw e;
}
});
});
}
}
} Or provide us a patch with the fix. |
When I hibernate my computer and turn it on again, the problem can be reproduced stably. I added the close and exit events of backendProcess to ElectronMainApplication, and found that the signal values are both SIGPIPE. Node.js Process ignores SIGPIPE errors by default, but it doesn't seem to take effect in the Electron environment. I tried adding the following code to BackendApplication, which seems to solve the problem.
electron issues reference:electron/electron#13254 (comment) |
Bug Description:
Two problems that can be reproduced stably.
Steps to Reproduce:
When I opened the Electron desktop application built on Theia, and did not operate for a period of time, when I opened DevTools, I could see the following error:
I click the exit button:
Error popup will pop up:
The code that caused the error is:
Additional Information
The text was updated successfully, but these errors were encountered: