Skip to content

Commit

Permalink
v0.9.84 [node_publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
scholarsmate committed Feb 17, 2025
1 parent 546bb79 commit 895c021
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.13)

# Project information
project(omega_edit
VERSION 0.9.83
VERSION 0.9.84
DESCRIPTION "Apache open source library for building editors"
HOMEPAGE_URL "https://github.com/ctc-oss/omega-edit"
LANGUAGES C CXX)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@omega-edit/core",
"version": "0.9.83",
"version": "0.9.84",
"private": "true",
"description": "OmegaEdit Client and Server",
"publisher": "CTC-OSS",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@omega-edit/client",
"version": "0.9.83",
"version": "0.9.84",
"description": "OmegaEdit gRPC Client",
"publisher": "ctc-oss",
"main": "./main.js",
Expand Down Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@grpc/grpc-js": "1.12.2",
"@omega-edit/server": "0.9.83",
"@omega-edit/server": "0.9.84",
"@types/google-protobuf": "3.15.12",
"google-protobuf": "3.21.4",
"pid-port": "1.0.2",
Expand Down
76 changes: 38 additions & 38 deletions packages/client/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,57 +185,57 @@ function isPortAvailable(port: number, host: string): Promise<boolean> {
}

/**
* Stop the server
* @param pid pid of the server process
* @returns true if the server was stopped, false otherwise
* Sends a specified signal to a given PID and optionally falls back to SIGKILL
* if the process fails to stop within the retry limit.
* @param pid process id
* @param signal signal to send to the process (default: SIGTERM)
* @param maxRetries maximum number of retries before falling back to SIGKILL (default: 10)
* @param fallbackToKill whether to fallback to SIGKILL if the process fails to stop (default: true)
* @returns true if the process was stopped, false otherwise
*/
export async function stopProcessUsingPID(
pid: number,
signal: string = 'SIGTERM'
signal: string = 'SIGTERM',
maxRetries: number = 10,
fallbackToKill: boolean = true
): Promise<boolean> {
const logMetadata = {
fn: 'stopProcessUsingPID',
pid,
signal,
}
const log = getLogger()
log.debug(logMetadata)
try {
process.kill(pid, signal)
// yield for a moment to allow the server to process the shutdown
const delayMs = Math.ceil(KILL_YIELD_MS / 10)
for (let i = 0; i < 10; ++i) {
const logMetadata = { fn: 'stopProcessUsingPID', pid, signal }
const delayMs = Math.ceil(KILL_YIELD_MS / maxRetries)

for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
process.kill(pid, signal)
await delay(delayMs)
if (!pidIsRunning(pid)) {
break
log.debug({ ...logMetadata, stopped: true, attempt })
return true
}
}
if (pidIsRunning(pid)) {
log.error({
...logMetadata,
stopped: false,
msg: 'process failed to stop',
})
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ESRCH') {
log.debug({ ...logMetadata, stopped: true, msg: 'already stopped' })
return true
}
log.error({ ...logMetadata, stopped: false, err: { msg: String(err) } })
return false
}
log.debug({ ...logMetadata, stopped: true })
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ESRCH') {
log.debug({
...logMetadata,
stopped: true,
msg: 'process already stopped',
})
} else {
log.error({
...logMetadata,
stopped: false,
err: { msg: String(err) },
})
}

if (fallbackToKill) {
try {
process.kill(pid, 'SIGKILL')
await delay(delayMs)
const stopped = !pidIsRunning(pid)
log.debug({ ...logMetadata, stopped, msg: 'fallback SIGKILL used' })
return stopped
} catch (err) {
log.error({ ...logMetadata, stopped: false, err: { msg: String(err) } })
return false
}
}
return true

log.error({ ...logMetadata, stopped: false, msg: 'failed to stop' })
return false
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ module.exports = {
},
],
},
optimization: {
usedExports: true,
minimize: true,
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@omega-edit/server",
"version": "0.9.83",
"version": "0.9.84",
"description": "OmegaEdit gRPC Server",
"publisher": "ctc-oss",
"main": "./out/index.js",
Expand Down

0 comments on commit 895c021

Please sign in to comment.