fix: iframe postMessage race condition — wasm 초기화 대기 (#522)#581
Conversation
message handler가 initialize() 완료를 기다리지 않아 'ready' 응답 후 즉시 loadFile 호출 시 __wbindgen_malloc undefined 에러 또는 timeout이 발생했다. 모든 RPC 메서드(ready, loadFile, pageCount, getPageSvg, exportHwp)와 레거시 hwpctl-load 경로에 await initPromise를 추가하여 wasm 초기화 완료 후에만 응답하도록 수정. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a race condition in rhwp-studio’s iframe postMessage RPC bridge where the parent could receive a "ready" response before WASM initialization finished, causing intermittent __wbindgen_malloc undefined errors or loadFile timeouts (Issue #522).
Changes:
- Capture
initialize()asinitPromiseand await it before serving iframe RPC methods. - Gate
"ready","loadFile","pageCount","getPageSvg","exportHwp", and legacy"hwpctl-load"behind initialization completion.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const initPromise = initialize(); | ||
|
|
| case 'ready': | ||
| // wasm 초기화 완료 후에만 true 응답 — race condition 방지 (#522) | ||
| await initPromise; | ||
| reply(true); | ||
| break; |
cherry-pick: - de5be58 (9ecc975): fix: iframe postMessage race condition — wasm 초기화 대기 (#522) 본질: - rhwp-studio/src/main.ts +11/-4 (단일 파일) - initPromise 캡처 + 모든 RPC 메서드에 await initPromise 추가 검증: - npx tsc --noEmit (rhwp-studio): 0 errors - cherry-pick 충돌 0 - WASM 영향 없음 (TS 만 변경) 작성자: @oksure (Hyunwoo Park) — 신규 컨트리뷰터 첫 PR closes #522 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@oksure 님, 첫 PR 환영합니다. cherry-pick 머지로 devel 에 반영했습니다 (devel `ddabc4b`). 머지된 commit
author 는 @oksure 으로 보존되었습니다. 검증
정합한 영역 인정본 PR 의 정합한 영역:
컨트리뷰터께 부탁드리는 사항 — devel 동기화본 PR base 가 본 환경 devel 의 매우 이전 시점 (`30351cdf` 추정) 으로 분기되어 있어 PR 변경 stat 에 본 환경 최근 변경분이 모두 "삭제" 로 표시되었습니다 (실제 본 commit 의 변경은 단일 파일이지만, base 차이로 인한 history skew). 다음 PR 작업 전에 본 환경 `devel` 동기화 부탁드립니다: ```bash 본 repo 를 upstream 으로 등록 (1회)git remote add upstream https://github.com/edwardkim/rhwp.git devel 동기화git fetch upstream 새 task branch 분기git checkout -b contrib/your-next-task 이렇게 하면 다음 PR 의 변경 stat 이 본질 commit 만으로 표시되어 검토가 더 빠릅니다. 이슈 #522 close본 PR closes #522 명시 + 정정 적용으로 자동 close 처리 (수동 close 도 진행). 처리 보고서: `mydocs/pr/archives/pr_581_report.md` 다시 한 번 첫 PR 감사드립니다. 매우 인상적인 PR 형식이었고 race condition 의 본질을 정확히 식별하셨습니다. |
- mydocs/pr/pr_581_report.md → archives/ Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cherry-pick: - 21fe401 (8dc75f6): fix: 그룹 내 그림(Picture) 직렬화 구현 + 라운드트립 테스트 본질: - src/serializer/control.rs +13/-2 (serialize_group_child Picture 분기) - src/serializer/control/tests.rs +79 (라운드트립 테스트 신규) - 기존 단독 Picture 직렬화와 동일 패턴 적용 · HWPTAG_SHAPE_COMPONENT (comp_level) · HWPTAG_SHAPE_COMPONENT_PICTURE (type_level) - 다른 그룹 자식 (Line/Rectangle/Ellipse/Chart/OLE) 과 동일 구조 검증: - cargo test --lib 1125 passed (신규 test_roundtrip_group_picture_child GREEN) - 회귀 0 (issue_505/530/546/418/501/svg_snapshot) - cargo clippy --lib 0 건 직렬화 영역 (저장 시 누락 정정), 시각 영향 없음 — B 처리 (라운드트립 테스트로 결정적 검증). 작성자: @oksure (Hyunwoo Park) — 세 번째 PR (PR #581/#582 후속) PR #428 후속 — Copilot 리뷰 피드백 (라운드트립 테스트 부재) 반영. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…commit) 본 PR 은 외부 컨트리뷰터 @oksure (Hyunwoo Park) 의 세 번째 PR (PR #581/#582 후속). cherry-pick: - 21fe401 (8dc75f6): fix: 그룹 내 그림(Picture) 직렬화 구현 + 라운드트립 테스트 · src/serializer/control.rs +13/-2 · src/serializer/control/tests.rs +79 본질: serialize_group_child 의 ShapeObject::Picture TODO 빈 분기 → 단독 Picture 직렬화와 동일 패턴 적용 (HWPTAG_SHAPE_COMPONENT + HWPTAG_SHAPE_COMPONENT_PICTURE). PR #428 후속 (Copilot 리뷰 피드백 반영, 라운드트립 테스트 포함). 검증: - cargo test --lib 1125 passed (신규 GREEN +1) - test_roundtrip_group_picture_child 통과 - 회귀 0 (issue_505/530/546/418/501/svg_snapshot) - cargo clippy --lib 0 건 작업지시자 의견 정합 (HWP 직렬화 영역, PR #553 close 시 명시).
- mydocs/pr/archives/pr_558_review.md (검토 문서) - mydocs/pr/archives/pr_558_report.md (처리 보고서) - mydocs/orders/20260504.md: PR #581/582/583/578-579/558 항목 추가
문제
@rhwp/editorwrapper의_waitReady()→loadFile호출 시:__wbindgen_malloc undefined즉시 실패Request timeout: loadFile(10초 후)두 패턴이 무작위로 발생. 원인:
rhwp-studio/src/main.ts의 message handler가initialize()완료 여부와 무관하게 즉시 등록되고,'ready'메서드가 wasm 상태확인 없이
reply(true)반환.원인 분석
해결
initialize()반환 Promise를initPromise로 캡처하고, 모든 RPC 메서드에서await initPromise후 응답:ready: 초기화 완료 후에만true응답loadFile,pageCount,getPageSvg,exportHwp: 초기화 대기 후 실행hwpctl-load: 동일 가드 추가검증
npx tsc --noEmit— 기존@types/chrome누락 1건 외 에러 없음 (기존)cargo test+cargo clippy -- -D warnings통과Closes #522