8000 Align relay shutdown with effective launchd limit by hmmhmmhm · Pull Request #401 · hmmhmmhm/daiso-mcp · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
8 changes: 4 additions & 4 deletions docs/dtryx-relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ node --max-old-space-size=128 --env-file=/absolute/path/dtryx.env \

### LaunchAgent 종료 유예

`scripts/relay/install-macos.py`는 올리브영과 터널용입니다. 디트릭스 런타임을 설치하거나 갱신할 때는 `page.aka.daiso-dtryx`의 **스테이징 plist**에서 기존 `ExitTimeOut`을 정수 80초로 설정하고 검증합니다.
`scripts/relay/install-macos.py`는 올리브영과 터널용입니다. 디트릭스 런타임을 설치하거나 갱신할 때는 `page.aka.daiso-dtryx`의 **스테이징 plist**에서 기존 `ExitTimeOut`을 정수 60초로 설정하고 검증합니다.

```sh
plutil -replace ExitTimeOut -integer 80 "$candidate_plist"
plutil -replace ExitTimeOut -integer 60 "$candidate_plist"
plutil -lint "$candidate_plist"
test "$(plutil -extract ExitTimeOut raw -expect integer "$candidate_plist")" = 80
test "$(plutil -extract ExitTimeOut raw -expect integer "$candidate_plist")" = 60
```

검증한 런타임과 함께 이 plist를 등록합니다. 디스크의 plist만 고쳐도 현재 로드된 작업의 종료 유예가 바뀌지는 않습니다. 기존 런타임과 짧은 종료 유예가 적용된 첫 전환에서는 진행 중인 요청의 완료를 보장할 수 없습니다. 올리브영과 터널의 plist는 이 설정의 대상에서 제외합니다.

종료 신호를 받으면 새 요청을 막고 이미 받은 요청의 연결, 내부 처리, GS25 갱신과 세븐 Safari 정리를 최대 65초 기다립니다. 요청 처리 15초, Safari helper의 최대 45초, 종료 콜백 여유 5초를 반영한 값입니다. launchd의 80초는 미확인 상태를 기록하고 로그를 비울 여유를 줍니다. macOS에서 운영할 때는 이 LaunchAgent를 사용합니다.
종료 신호를 받으면 새 요청을 막고 추적 중인 연결과 내부 작업을 최대 50초 기다립니다. 현재 관측한 Dtryx LaunchAgent의 loaded `ExitTimeOut` 60초보다 짧게 두어 미확인 상태를 기록하고 로그를 비울 시간을 남깁니다. 이 제한 시간은 Safari helper의 완료나 창 회수를 보장하지 않습니다. 제한 시간 내 작업이 끝나지 않으면 `shutdown-uncertain`으로 기록하며, launchd가 60초 뒤 프로세스를 강제 종료할 수 있습니다. 이 경우 PID 종료나 포트 폐쇄만으로 대상 Safari 창 회수를 추정하지 않습니다. macOS에 적용할 때는 plist를 등록한 뒤 loaded `launchctl print`의 종료 유예가 60초인지 확인합니다. 디스크 plist 변경만으로 loaded 설정은 바뀌지 않습니다.

대상 프로세스의 종료 이벤트가 `shutdown-drained`이면 추적한 로컬 작업이 모두 끝났습니다. 각 요청의 성공 여부는 해당 요청 결과에서 확인합니다. `shutdown-uncertain`이면 종료 코드는 1이며, 로그가 누락되거나 launchd가 프로세스를 강제 종료한 경우에도 정리가 확인되지 않은 상태로 처리합니다. 남아 있는 소유 창과 잠금은 해당 작업의 증거로 보존합니다. PID가 사라졌거나 포트가 닫혔다는 사실만으로 창 회수를 확인할 수 없습니다.

Expand Down
2 changes: 1 addition & 1 deletion docs/gs25-auth-recovery-runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ launchctl kill SIGTERM gui/$(id -u)/page.aka.daiso-dtryx
# 아래 설치·검증을 마칠 때까지 kickstart하지 않는다.
```

[디트릭스 LaunchAgent 종료 유예](dtryx-relay.md#launchagent-종료-유예)를 적용한 버전에서는 해당 프로세스의 `shutdown-drained`와 종료를 확인한다. `shutdown-uncertain`, 완료 기록 누락 또는 강제 종료가 있으면 GS25 갱신과 세븐 창 정리 상태를 확인할 때까지 정상 종료로 기록하지 않는다. 비정상 종료 뒤 KeepAlive가 후속 프로세스를 띄울 수 있으므로 기존 PID의 종료만으로 세션 파일을 교체하지 않는다. 새 중계도 없는 상태를 확인한 뒤에만 다음 단계로 간다.
[디트릭스 LaunchAgent 종료 유예](dtryx-relay.md#launchagent-종료-유예)를 적용한 버전에서는 loaded `ExitTimeOut`이 60초인지 확인하고 해당 프로세스의 `shutdown-drained`와 종료를 확인한다. 내부 drain은 최대 50초이며 Safari 창 회수를 보장하지 않는다. `shutdown-uncertain`, 완료 기록 누락 또는 강제 종료가 있으면 GS25 갱신과 세븐 창 정리 상태를 확인할 때까지 정상 종료로 기록하지 않는다. 비정상 종료 뒤 KeepAlive가 후속 프로세스를 띄울 수 있으므로 기존 PID의 종료만으로 세션 파일을 교체하지 않는다. 새 중계도 없는 상태를 확인한 뒤에만 다음 단계로 간다.

3. 종료된 상태에서 비공개 백업 디렉터리(0700)에 변경할 runtime 파일·`dtryx.env`·기존 GS 세션을 백업한다. 환경/세션 백업도 0600으로 유지한다. `quota.json`과 상태 디렉터리를 삭제·교체하지 않는다.
4. 세션을 목적 디렉터리의 **새 0600 임시 파일**로 쓴 뒤 `os.replace`/rename으로 `gs25-auth.json`에 교체한다. 내용은 세 필드만 저장한다. 그룹/다른 사용자 권한이 열린 파일은 중계가 거절한다.
Expand Down
6 changes: 3 additions & 3 deletions scripts/relay/dtryx-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import { createCgvRelay } from './cgv.js';
import { createDtryxRelay } from './dtryx.js';
import { createRelayDrain } from './dtryx-drain.js';

// Allow 15 seconds for an admitted request and 45 for its Safari helper, with callback margin.
// The Dtryx LaunchAgent allows 80 seconds so unresolved work can be recorded before termination.
const shutdownDeadlineMs = 65000;
// Keep the drain deadline below the observed 60-second Dtryx LaunchAgent timeout.
// This is a bounded wait, not a guarantee that Safari has reclaimed its owned window.
const shutdownDeadlineMs = 50000;

let logger: ReturnType<typeof createRelayLogger> | undefined;
async function main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/relay/dtryx-start-cgv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ it('reports shutdown uncertainty when an operation exceeds the deadline', async
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
const stopped = close?.();
close = undefined;
await vi.advanceTimersByTimeAsync(64999);
await vi.advanceTimersByTimeAsync(49999);
expect(state.log).not.toHaveBeenCalledWith({ stage: 'process', outcome: 'shutdown-uncertain' });
expect(state.closeAllConnections).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(1);
Expand Down
Loading
0