Skip to content

Commit 895c021

Browse files
committed
v0.9.84 [node_publish]
1 parent 546bb79 commit 895c021

File tree

6 files changed

+47
-43
lines changed

6 files changed

+47
-43
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.13)
1313

1414
# Project information
1515
project(omega_edit
16-
VERSION 0.9.83
16+
VERSION 0.9.84
1717
DESCRIPTION "Apache open source library for building editors"
1818
HOMEPAGE_URL "https://github.com/ctc-oss/omega-edit"
1919
LANGUAGES C CXX)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omega-edit/core",
3-
"version": "0.9.83",
3+
"version": "0.9.84",
44
"private": "true",
55
"description": "OmegaEdit Client and Server",
66
"publisher": "CTC-OSS",

packages/client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omega-edit/client",
3-
"version": "0.9.83",
3+
"version": "0.9.84",
44
"description": "OmegaEdit gRPC Client",
55
"publisher": "ctc-oss",
66
"main": "./main.js",
@@ -44,7 +44,7 @@
4444
},
4545
"dependencies": {
4646
"@grpc/grpc-js": "1.12.2",
47-
"@omega-edit/server": "0.9.83",
47+
"@omega-edit/server": "0.9.84",
4848
"@types/google-protobuf": "3.15.12",
4949
"google-protobuf": "3.21.4",
5050
"pid-port": "1.0.2",

packages/client/src/server.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -185,57 +185,57 @@ function isPortAvailable(port: number, host: string): Promise<boolean> {
185185
}
186186

187187
/**
188-
* Stop the server
189-
* @param pid pid of the server process
190-
* @returns true if the server was stopped, false otherwise
188+
* Sends a specified signal to a given PID and optionally falls back to SIGKILL
189+
* if the process fails to stop within the retry limit.
190+
* @param pid process id
191+
* @param signal signal to send to the process (default: SIGTERM)
192+
* @param maxRetries maximum number of retries before falling back to SIGKILL (default: 10)
193+
* @param fallbackToKill whether to fallback to SIGKILL if the process fails to stop (default: true)
194+
* @returns true if the process was stopped, false otherwise
191195
*/
192196
export async function stopProcessUsingPID(
193197
pid: number,
194-
signal: string = 'SIGTERM'
198+
signal: string = 'SIGTERM',
199+
maxRetries: number = 10,
200+
fallbackToKill: boolean = true
195201
): Promise<boolean> {
196-
const logMetadata = {
197-
fn: 'stopProcessUsingPID',
198-
pid,
199-
signal,
200-
}
201202
const log = getLogger()
202-
log.debug(logMetadata)
203-
try {
204-
process.kill(pid, signal)
205-
// yield for a moment to allow the server to process the shutdown
206-
const delayMs = Math.ceil(KILL_YIELD_MS / 10)
207-
for (let i = 0; i < 10; ++i) {
203+
const logMetadata = { fn: 'stopProcessUsingPID', pid, signal }
204+
const delayMs = Math.ceil(KILL_YIELD_MS / maxRetries)
205+
206+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
207+
try {
208+
process.kill(pid, signal)
208209
await delay(delayMs)
209210
if (!pidIsRunning(pid)) {
210-
break
211+
log.debug({ ...logMetadata, stopped: true, attempt })
212+
return true
211213
}
212-
}
213-
if (pidIsRunning(pid)) {
214-
log.error({
215-
...logMetadata,
216-
stopped: false,
217-
msg: 'process failed to stop',
218-
})
214+
} catch (err) {
215+
if ((err as NodeJS.ErrnoException).code === 'ESRCH') {
216+
log.debug({ ...logMetadata, stopped: true, msg: 'already stopped' })
217+
return true
218+
}
219+
log.error({ ...logMetadata, stopped: false, err: { msg: String(err) } })
219220
return false
220221
}
221-
log.debug({ ...logMetadata, stopped: true })
222-
} catch (err) {
223-
if ((err as NodeJS.ErrnoException).code === 'ESRCH') {
224-
log.debug({
225-
...logMetadata,
226-
stopped: true,
227-
msg: 'process already stopped',
228-
})
229-
} else {
230-
log.error({
231-
...logMetadata,
232-
stopped: false,
233-
err: { msg: String(err) },
234-
})
222+
}
223+
224+
if (fallbackToKill) {
225+
try {
226+
process.kill(pid, 'SIGKILL')
227+
await delay(delayMs)
228+
const stopped = !pidIsRunning(pid)
229+
log.debug({ ...logMetadata, stopped, msg: 'fallback SIGKILL used' })
230+
return stopped
231+
} catch (err) {
232+
log.error({ ...logMetadata, stopped: false, err: { msg: String(err) } })
235233
return false
236234
}
237235
}
238-
return true
236+
237+
log.error({ ...logMetadata, stopped: false, msg: 'failed to stop' })
238+
return false
239239
}
240240

241241
/**

packages/client/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ module.exports = {
5050
},
5151
],
5252
},
53+
optimization: {
54+
usedExports: true,
55+
minimize: true,
56+
},
5357
plugins: [
5458
new webpack.ProgressPlugin(),
5559
new CleanWebpackPlugin(),

packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omega-edit/server",
3-
"version": "0.9.83",
3+
"version": "0.9.84",
44
"description": "OmegaEdit gRPC Server",
55
"publisher": "ctc-oss",
66
"main": "./out/index.js",

0 commit comments

Comments
 (0)