next-issue 6.6.7 → 6.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -10
- package/dist/gate.mjs +32 -10
- package/dist/handover.mjs +12 -1
- package/dist/implement.mjs +1 -6
- package/dist/lock.mjs +117 -47
- package/dist/serve.mjs +16 -19
- package/dist/worker-server.mjs +15 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,10 +129,11 @@ the run handles one issue. For each issue:
|
|
|
129
129
|
reruns the failed jobs once with `gh run rerun <id> --failed`, records a
|
|
130
130
|
`main-checks.rerun` event, saves the rerun in the state file and waits
|
|
131
131
|
again once the runs restart. When the rerun cannot start, or the checks
|
|
132
|
-
fail again, the fixer gets their logs from the check budget, and its fix
|
|
133
|
-
the same way. When the fixer cannot fix them, its fix cannot land,
|
|
134
|
-
budget runs out, the harness reverts every
|
|
135
|
-
base branch, pushes the revert and hands the
|
|
132
|
+
fail again, the fixer gets their logs from the check budget, and its fix
|
|
133
|
+
lands the same way. When the fixer cannot fix them, its fix cannot land,
|
|
134
|
+
an error stops the fix, or the budget runs out, the harness reverts every
|
|
135
|
+
commit of the change on the base branch, pushes the revert and hands the
|
|
136
|
+
issue to a person. A revert
|
|
136
137
|
push that the remote refuses, for example because the base moved, makes
|
|
137
138
|
the revert again on the new base, three times at most. A resume
|
|
138
139
|
that stopped while the checks of a landed commit ran waits for them
|
|
@@ -189,9 +190,10 @@ and comments the reason on the issue, when:
|
|
|
189
190
|
branches go away with the `<n>` branch when the issue is done;
|
|
190
191
|
- the reviewer gives no verdict, or the checks do not finish in time;
|
|
191
192
|
- the push to the base branch fails three times;
|
|
192
|
-
- the checks on the base branch fail and the fixer cannot fix them,
|
|
193
|
-
do not finish in time. The base branch is then
|
|
194
|
-
no new issue and ends once the running issues
|
|
193
|
+
- the checks on the base branch fail and the fixer cannot fix them, an error
|
|
194
|
+
stops the fix, or they do not finish in time. The base branch is then
|
|
195
|
+
broken, so the run claims no new issue and ends once the running issues
|
|
196
|
+
end;
|
|
195
197
|
- an agent does not finish in `agentTimeoutMinutes`;
|
|
196
198
|
- the setup command fails, or does not finish in `setupTimeoutMinutes`;
|
|
197
199
|
- a step of the run fails with an error. A `gh` call that is safe to repeat,
|
|
@@ -452,7 +454,9 @@ the prompt asks them to keep only what still holds. The reviewer only reads it.
|
|
|
452
454
|
|
|
453
455
|
When the implementer makes no change, the hand-over comment holds its full
|
|
454
456
|
reply after the note, so its reasons and questions can be answered on the issue.
|
|
455
|
-
|
|
457
|
+
Every hand-over comment is cut to fit a GitHub comment, whatever the reason, so a
|
|
458
|
+
long reply or a long run error does not lose it. A cut comment ends with a line
|
|
459
|
+
that says so.
|
|
456
460
|
|
|
457
461
|
A hand-over marks the state file as handed over. To give the issue another try,
|
|
458
462
|
take the `status:needs-human` label off, or answer the hand-over. The next run
|
|
@@ -558,8 +562,9 @@ affect another. The worker:
|
|
|
558
562
|
A lock without a start time, from an older version, is stale too. A worker
|
|
559
563
|
that cannot read its own start time exits with an error and takes no lock.
|
|
560
564
|
When several workers start at once, one takes the lock and the others exit
|
|
561
|
-
with `another worker is running`. A worker that stops removes the
|
|
562
|
-
|
|
565
|
+
with `another worker is running`. A worker that stops removes the lock file
|
|
566
|
+
only while it still holds the lock, and the socket file only while it is
|
|
567
|
+
still the socket it bound;
|
|
563
568
|
- refuses a `start`, `stop` or `questions` message whose `root` is not
|
|
564
569
|
the exact path of its repository with an `error` message, and starts or
|
|
565
570
|
stops nothing;
|
package/dist/gate.mjs
CHANGED
|
@@ -48,30 +48,52 @@ async function failedChecksFix(job, sha) {
|
|
|
48
48
|
const { repo, config, ports, base } = context;
|
|
49
49
|
const { round, limit } = budgetUse(job, 'ciFixes');
|
|
50
50
|
if (round >= limit) {
|
|
51
|
-
const reverted = await
|
|
51
|
+
const reverted = await revertOrReport(job);
|
|
52
52
|
return escalateAndFinish(job, `The checks on ${base} failed and the limit of ${limit} check fixes was reached.${reverted}`, 'check budget');
|
|
53
53
|
}
|
|
54
54
|
state.ciFixes += 1;
|
|
55
55
|
await writeState(repo, state);
|
|
56
|
-
|
|
56
|
+
let logs;
|
|
57
|
+
try {
|
|
58
|
+
logs = await ports.failedBaseLogs(repo, sha, config.logMaxChars);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return escalateError(job, error, `The read of the failed checks on ${base} failed`, 'logs error');
|
|
62
|
+
}
|
|
57
63
|
log.event('main-checks.logs', { chars: logs.length });
|
|
58
64
|
let fix;
|
|
59
65
|
try {
|
|
60
66
|
fix = await fixRound(job, `The checks on ${base} failed after the change landed there.`, logs, [], 'checks');
|
|
61
67
|
}
|
|
62
68
|
catch (error) {
|
|
63
|
-
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
const reverted = await revert(job);
|
|
67
|
-
const detail = message(error);
|
|
68
|
-
const stop = detail.endsWith('.') ? '' : '.';
|
|
69
|
-
return escalateAndFinish(job, `The fixer for the failed checks on ${base} failed: ${detail}${stop}${reverted}`, 'fixer error');
|
|
69
|
+
return escalateError(job, error, `The fixer for the failed checks on ${base} failed`, 'fixer error');
|
|
70
70
|
}
|
|
71
71
|
if (!fix.committed) {
|
|
72
|
-
const reverted = await
|
|
72
|
+
const reverted = await revertOrReport(job);
|
|
73
73
|
return escalateCheckFix(job, fix.unrelated, `checks on ${base}`, reverted);
|
|
74
74
|
}
|
|
75
75
|
job.repairing = true;
|
|
76
76
|
return GATE_FIXED;
|
|
77
77
|
}
|
|
78
|
+
async function escalateError(job, error, note, reason) {
|
|
79
|
+
if (runStopped()) {
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
const reverted = await revertOrReport(job);
|
|
83
|
+
return escalateAndFinish(job, `${note}: ${sentence(message(error))}${reverted}`, reason);
|
|
84
|
+
}
|
|
85
|
+
async function revertOrReport(job) {
|
|
86
|
+
try {
|
|
87
|
+
return await revert(job);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (runStopped()) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
job.repairing = false;
|
|
94
|
+
return ` The revert of the change on ${job.context.base} failed: ${sentence(message(error))}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function sentence(text) {
|
|
98
|
+
return text.endsWith('.') ? text : `${text}.`;
|
|
99
|
+
}
|
package/dist/handover.mjs
CHANGED
|
@@ -89,7 +89,18 @@ async function handOver(context, log, issue, state, reason) {
|
|
|
89
89
|
log.event('hand-over', { reason }, 'quiet');
|
|
90
90
|
await writeState(repo, { ...state, handedOver: true });
|
|
91
91
|
await setStatus(context, issue, config.labels.needsHuman);
|
|
92
|
-
await ports.commentOnIssue(repo, issue,
|
|
92
|
+
await ports.commentOnIssue(repo, issue, handOverComment(reason));
|
|
93
|
+
}
|
|
94
|
+
const COMMENT_LIMIT = 65536;
|
|
95
|
+
const CUT = '\n\nThe reason was too long for a GitHub comment and was cut.';
|
|
96
|
+
function handOverComment(reason) {
|
|
97
|
+
const comment = `${HAND_OVER} ${reason}`;
|
|
98
|
+
if (comment.length <= COMMENT_LIMIT) {
|
|
99
|
+
return comment;
|
|
100
|
+
}
|
|
101
|
+
const end = COMMENT_LIMIT - CUT.length;
|
|
102
|
+
const splitsPair = /[\uD800-\uDBFF]/.test(comment.charAt(end - 1));
|
|
103
|
+
return `${comment.slice(0, splitsPair ? end - 1 : end)}${CUT}`;
|
|
93
104
|
}
|
|
94
105
|
export async function claimedError(context, log, issue, state, error, started) {
|
|
95
106
|
const { reason } = logIssueError(log, error, started);
|
package/dist/implement.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parseCommitSubject } from './agent-reply.mjs';
|
|
2
2
|
import { CODING } from './agents.mjs';
|
|
3
3
|
import { commitWork } from './fix.mjs';
|
|
4
|
-
import { HAND_OVER } from './hand-over-comments.mjs';
|
|
5
4
|
import { escalateAndFinish } from './handover.mjs';
|
|
6
5
|
import { fallbackTitle, ROUND_CONTINUE, runRole } from './job.mjs';
|
|
7
6
|
import { implementPrompt } from './prompts.mjs';
|
|
@@ -33,14 +32,10 @@ async function useEarlierCommit(job) {
|
|
|
33
32
|
return undefined;
|
|
34
33
|
}
|
|
35
34
|
const NO_CHANGE = 'The implementer produced no change.';
|
|
36
|
-
const COMMENT_LIMIT = 65536;
|
|
37
|
-
const CUT = '\n\nThe reply was too long for a GitHub comment and was cut.';
|
|
38
35
|
function noChangeNote(reply) {
|
|
39
36
|
const text = reply.trim();
|
|
40
37
|
if (text === '') {
|
|
41
38
|
return NO_CHANGE;
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
const room = COMMENT_LIMIT - HAND_OVER.length - 1;
|
|
45
|
-
return note.length > room ? `${note.slice(0, room - CUT.length)}${CUT}` : note;
|
|
40
|
+
return `${NO_CHANGE}\n\n${text}`;
|
|
46
41
|
}
|
package/dist/lock.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { readFileSync, statSync } from 'node:fs';
|
|
4
|
-
import { link, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { link, open, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { basename, dirname, join } from 'node:path';
|
|
5
6
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
7
|
import { promisify } from 'node:util';
|
|
7
8
|
import { hasCode } from './errors.mjs';
|
|
8
|
-
import {
|
|
9
|
+
import { readTextOrEmpty, unlessMissing } from './files.mjs';
|
|
9
10
|
const LOCK_POLL_MS = 100;
|
|
10
11
|
const worktreeQueues = new Map();
|
|
11
12
|
export function oneAtATime(root, work) {
|
|
@@ -40,84 +41,153 @@ async function holderOf(text) {
|
|
|
40
41
|
async function holder(lockPath) {
|
|
41
42
|
return holderOf(await readTextOrEmpty(lockPath));
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return text !== undefined && (await holderOf(text)) === undefined;
|
|
44
|
+
function idOf(found) {
|
|
45
|
+
return `${found.dev}:${found.ino}`;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (pid !== undefined) {
|
|
50
|
-
process.kill(pid, 'SIGTERM');
|
|
51
|
-
}
|
|
52
|
-
return pid;
|
|
47
|
+
function draftPath(path) {
|
|
48
|
+
return `${path}.${process.pid}.${randomUUID()}`;
|
|
53
49
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
50
|
+
async function lockState(path) {
|
|
51
|
+
const read = await unlessMissing(async () => {
|
|
52
|
+
const file = await open(path, 'r');
|
|
53
|
+
try {
|
|
54
|
+
return { id: idOf(await file.stat()), text: await file.readFile('utf8') };
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await file.close();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (read === undefined) {
|
|
61
|
+
return { state: 'missing' };
|
|
62
|
+
}
|
|
63
|
+
return { state: (await holderOf(read.text)) === undefined ? 'stale' : 'held', id: read.id };
|
|
56
64
|
}
|
|
57
|
-
function
|
|
65
|
+
async function take(path, text) {
|
|
66
|
+
const draft = draftPath(path);
|
|
67
|
+
await writeFile(draft, text, { flag: 'wx', mode: 0o600 });
|
|
58
68
|
try {
|
|
59
|
-
|
|
69
|
+
await link(draft, path);
|
|
70
|
+
return idOf(await stat(draft));
|
|
60
71
|
}
|
|
61
|
-
catch {
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (!hasCode(error, 'EEXIST')) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
62
76
|
return undefined;
|
|
63
77
|
}
|
|
78
|
+
finally {
|
|
79
|
+
await rm(draft, { force: true });
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
|
-
async function
|
|
82
|
+
async function removeIfSame(path, id) {
|
|
83
|
+
const moved = draftPath(path);
|
|
66
84
|
try {
|
|
67
|
-
await
|
|
68
|
-
return true;
|
|
85
|
+
await rename(path, moved);
|
|
69
86
|
}
|
|
70
87
|
catch (error) {
|
|
71
|
-
if (hasCode(error, '
|
|
72
|
-
return
|
|
88
|
+
if (hasCode(error, 'ENOENT')) {
|
|
89
|
+
return;
|
|
73
90
|
}
|
|
74
91
|
throw error;
|
|
75
92
|
}
|
|
93
|
+
try {
|
|
94
|
+
if (idOf(await stat(moved)) !== id) {
|
|
95
|
+
await link(moved, path).catch((error) => {
|
|
96
|
+
if (!hasCode(error, 'EEXIST')) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
await rm(moved, { force: true });
|
|
104
|
+
}
|
|
76
105
|
}
|
|
77
|
-
async function removeStale(path,
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
106
|
+
async function removeStale(path, text) {
|
|
107
|
+
const guard = `${path}.break`;
|
|
108
|
+
if ((await take(guard, text)) === undefined) {
|
|
109
|
+
const found = await lockState(guard);
|
|
110
|
+
if (found.state === 'stale') {
|
|
111
|
+
await removeIfSame(guard, found.id);
|
|
112
|
+
}
|
|
113
|
+
else if (found.state === 'held') {
|
|
114
|
+
await delay(LOCK_POLL_MS);
|
|
82
115
|
}
|
|
83
116
|
return;
|
|
84
117
|
}
|
|
85
118
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
119
|
+
const found = await lockState(path);
|
|
120
|
+
if (found.state === 'stale') {
|
|
121
|
+
await removeIfSame(path, found.id);
|
|
88
122
|
}
|
|
89
123
|
}
|
|
90
124
|
finally {
|
|
91
|
-
await rm(
|
|
125
|
+
await rm(guard, { force: true });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function isAlive(pid) {
|
|
129
|
+
try {
|
|
130
|
+
process.kill(pid, 0);
|
|
131
|
+
return true;
|
|
92
132
|
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
return !hasCode(error, 'ESRCH');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function removeDeadDrafts(path) {
|
|
138
|
+
const name = basename(path);
|
|
139
|
+
for (const entry of await readdir(dirname(path))) {
|
|
140
|
+
const pid = /^\.(?:break\.)?(\d+)\.[0-9a-f-]{36}$/.exec(entry.slice(name.length))?.[1];
|
|
141
|
+
if (entry.startsWith(name) && pid !== undefined && !isAlive(Number(pid))) {
|
|
142
|
+
await rm(join(dirname(path), entry), { force: true });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export async function stopWorker(lockPath) {
|
|
147
|
+
const pid = await holder(lockPath);
|
|
148
|
+
if (pid !== undefined) {
|
|
149
|
+
process.kill(pid, 'SIGTERM');
|
|
150
|
+
}
|
|
151
|
+
return pid;
|
|
152
|
+
}
|
|
153
|
+
function textOf(path) {
|
|
154
|
+
try {
|
|
155
|
+
return readFileSync(path, 'utf8');
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function heldLock(path, id, text) {
|
|
162
|
+
return {
|
|
163
|
+
owns: () => {
|
|
164
|
+
const found = statSync(path, { throwIfNoEntry: false });
|
|
165
|
+
return found !== undefined && idOf(found) === id && textOf(path) === text;
|
|
166
|
+
},
|
|
167
|
+
};
|
|
93
168
|
}
|
|
94
169
|
export async function lock(path, waitMs, readStart = processStart) {
|
|
95
170
|
const started = await readStart(process.pid);
|
|
96
171
|
if (started === undefined) {
|
|
97
172
|
throw new Error('next-issue: cannot read the start time of the worker process');
|
|
98
173
|
}
|
|
99
|
-
const filled = `${path}.${randomUUID()}`;
|
|
100
174
|
const text = `${process.pid} ${started}\n`;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
else if (Date.now() >= deadline) {
|
|
175
|
+
const deadline = Date.now() + waitMs;
|
|
176
|
+
for (;;) {
|
|
177
|
+
const id = await take(path, text);
|
|
178
|
+
if (id !== undefined) {
|
|
179
|
+
await removeDeadDrafts(path);
|
|
180
|
+
return heldLock(path, id, text);
|
|
181
|
+
}
|
|
182
|
+
const found = await lockState(path);
|
|
183
|
+
if (found.state === 'stale') {
|
|
184
|
+
await removeStale(path, text);
|
|
185
|
+
}
|
|
186
|
+
else if (found.state === 'held') {
|
|
187
|
+
if (Date.now() >= deadline) {
|
|
115
188
|
return undefined;
|
|
116
189
|
}
|
|
117
190
|
await delay(LOCK_POLL_MS);
|
|
118
191
|
}
|
|
119
192
|
}
|
|
120
|
-
finally {
|
|
121
|
-
await rm(filled, { force: true });
|
|
122
|
-
}
|
|
123
193
|
}
|
package/dist/serve.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs';
|
|
2
1
|
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
3
2
|
import { createServer } from 'node:http';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
5
4
|
import { WebSocketServer } from 'ws';
|
|
6
5
|
import { parseStartArgs } from './args.mjs';
|
|
7
6
|
import { stopChildren, withRunChildren } from './children.mjs';
|
|
8
7
|
import { message } from './errors.mjs';
|
|
9
|
-
import { listOrEmpty } from './files.mjs';
|
|
10
8
|
import { lock } from './lock.mjs';
|
|
11
9
|
import { startProgress } from './progress.mjs';
|
|
12
10
|
import { isNewer } from './protocol.mjs';
|
|
@@ -15,7 +13,7 @@ import { runRepo } from './run.mjs';
|
|
|
15
13
|
import { packageVersion } from './version.mjs';
|
|
16
14
|
import { checkSocketPath, workerPaths } from './worker-paths.mjs';
|
|
17
15
|
import { active, endStatus, newRun, requestStop, runControls, runsMessage, startRefusal, stopPoint, } from './worker-run.mjs';
|
|
18
|
-
import { broadcast, closer, listen, parseMessage, shutdown, } from './worker-server.mjs';
|
|
16
|
+
import { broadcast, closer, fileId, listen, parseMessage, removeOwned, shutdown, } from './worker-server.mjs';
|
|
19
17
|
const LOCK_WAIT_MS = 5_000;
|
|
20
18
|
const IDLE_MS = 30_000;
|
|
21
19
|
export async function startWorker(options) {
|
|
@@ -25,13 +23,12 @@ export async function startWorker(options) {
|
|
|
25
23
|
if (held === undefined) {
|
|
26
24
|
return undefined;
|
|
27
25
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
26
|
+
const owned = {
|
|
27
|
+
socketPath: options.socketPath,
|
|
28
|
+
lockPath: options.lockPath,
|
|
29
|
+
lock: held,
|
|
30
|
+
socket: '',
|
|
31
|
+
};
|
|
35
32
|
const runs = new Map();
|
|
36
33
|
let restart = false;
|
|
37
34
|
const server = createServer();
|
|
@@ -41,7 +38,7 @@ export async function startWorker(options) {
|
|
|
41
38
|
let idleTimer;
|
|
42
39
|
const { closed, close } = closer(async () => {
|
|
43
40
|
clearTimeout(idleTimer);
|
|
44
|
-
await shutdown(server, sockets,
|
|
41
|
+
await shutdown(server, sockets, owned);
|
|
45
42
|
});
|
|
46
43
|
const closeWhenIdle = () => {
|
|
47
44
|
if ((restart || sockets.clients.size === 0) && !busy()) {
|
|
@@ -128,10 +125,13 @@ export async function startWorker(options) {
|
|
|
128
125
|
}
|
|
129
126
|
});
|
|
130
127
|
});
|
|
131
|
-
|
|
132
|
-
await
|
|
128
|
+
const draft = join(dirname(options.socketPath), `~${basename(options.socketPath).slice(1)}`);
|
|
129
|
+
await rm(draft, { force: true });
|
|
130
|
+
await listen(server, draft);
|
|
131
|
+
await rename(draft, options.socketPath);
|
|
132
|
+
owned.socket = fileId(options.socketPath);
|
|
133
133
|
idleTimer = setTimeout(closeWhenIdle, options.idleMs ?? IDLE_MS);
|
|
134
|
-
return { closed, close,
|
|
134
|
+
return { closed, close, release: () => removeOwned(owned) };
|
|
135
135
|
}
|
|
136
136
|
export async function serve(root) {
|
|
137
137
|
const paths = workerPaths(root);
|
|
@@ -149,10 +149,7 @@ export async function serve(root) {
|
|
|
149
149
|
const end = (signal) => {
|
|
150
150
|
process.off('SIGTERM', onTerminate);
|
|
151
151
|
process.off('SIGINT', onInterrupt);
|
|
152
|
-
|
|
153
|
-
rmSync(paths.socketPath, { force: true });
|
|
154
|
-
rmSync(paths.lockPath, { force: true });
|
|
155
|
-
}
|
|
152
|
+
worker.release();
|
|
156
153
|
stopChildren(signal);
|
|
157
154
|
};
|
|
158
155
|
const onTerminate = () => end('SIGTERM');
|
package/dist/worker-server.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rmSync, statSync } from 'node:fs';
|
|
2
2
|
import { send } from './questions.mjs';
|
|
3
3
|
import { runsMessage } from './worker-run.mjs';
|
|
4
4
|
function isRecord(value) {
|
|
@@ -56,16 +56,25 @@ export function listen(server, path) {
|
|
|
56
56
|
function whenClosed(close) {
|
|
57
57
|
return new Promise((resolve) => close(() => resolve()));
|
|
58
58
|
}
|
|
59
|
-
export
|
|
59
|
+
export function fileId(path) {
|
|
60
|
+
const found = statSync(path, { throwIfNoEntry: false });
|
|
61
|
+
return found?.isSocket() === true ? `${found.dev}:${found.ino}` : '';
|
|
62
|
+
}
|
|
63
|
+
export function removeOwned(owned) {
|
|
64
|
+
if (owned.socket !== '' && fileId(owned.socketPath) === owned.socket) {
|
|
65
|
+
rmSync(owned.socketPath, { force: true });
|
|
66
|
+
}
|
|
67
|
+
if (owned.lock.owns()) {
|
|
68
|
+
rmSync(owned.lockPath, { force: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export async function shutdown(server, sockets, owned) {
|
|
60
72
|
for (const socket of sockets.clients) {
|
|
61
73
|
socket.terminate();
|
|
62
74
|
}
|
|
63
75
|
await whenClosed((done) => sockets.close(done));
|
|
64
76
|
await whenClosed((done) => server.close(done));
|
|
65
|
-
|
|
66
|
-
await rm(paths.socketPath, { force: true });
|
|
67
|
-
await rm(paths.lockPath, { force: true });
|
|
68
|
-
}
|
|
77
|
+
removeOwned(owned);
|
|
69
78
|
}
|
|
70
79
|
export function closer(stop) {
|
|
71
80
|
let finish = () => undefined;
|