Skip to content

fix: iframe postMessage race condition — wasm 초기화 대기 (#522)#581

Closed
oksure wants to merge 1 commit into
edwardkim:develfrom
oksure:contrib/fix-iframe-race-condition
Closed

fix: iframe postMessage race condition — wasm 초기화 대기 (#522)#581
oksure wants to merge 1 commit into
edwardkim:develfrom
oksure:contrib/fix-iframe-race-condition

Conversation

@oksure

@oksure oksure commented May 4, 2026

Copy link
Copy Markdown
Contributor

문제

@rhwp/editor wrapper의 _waitReady()loadFile 호출 시:

  1. __wbindgen_malloc undefined 즉시 실패
  2. Request timeout: loadFile (10초 후)

두 패턴이 무작위로 발생. 원인: rhwp-studio/src/main.ts의 message handler가
initialize() 완료 여부와 무관하게 즉시 등록되고, 'ready' 메서드가 wasm 상태
확인 없이 reply(true) 반환.

원인 분석

initialize() (async, 5-15s)
  ├─ loadWebFonts
  └─ wasm.initialize() ← 시간 소요

window.addEventListener('message', ...) ← 즉시 등록, initialize 대기 X
  case 'ready': reply(true)  ← wasm 미초기화 상태에서도 true
  case 'loadFile': wasm.loadDocument(...) ← throw

해결

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

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>
Copilot AI review requested due to automatic review settings May 4, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() as initPromise and 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.

Comment thread rhwp-studio/src/main.ts
Comment on lines +653 to 654
const initPromise = initialize();

Comment thread rhwp-studio/src/main.ts
Comment on lines +686 to +690
case 'ready':
// wasm 초기화 완료 후에만 true 응답 — race condition 방지 (#522)
await initPromise;
reply(true);
break;
edwardkim added a commit that referenced this pull request May 4, 2026
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>
@edwardkim

Copy link
Copy Markdown
Owner

@oksure 님, 첫 PR 환영합니다. cherry-pick 머지로 devel 에 반영했습니다 (devel `ddabc4b`).

머지된 commit

author 는 @oksure 으로 보존되었습니다.

검증

  • `npx tsc --noEmit` (rhwp-studio): 0 errors
  • cherry-pick 충돌 0
  • WASM 영향 없음 (TS 만 변경)

정합한 영역 인정

본 PR 의 정합한 영역:

  1. 단일 파일 + 작은 변경 (+11/-4) — 본질 명확 + 빠른 검토 가능
  2. PR 본문의 결함 분석 + 원인 코드 영역 + 정정 절차 명시 — 매우 정합한 작성 톤
  3. `closes iframe 임베드 시 loadFile race condition — 'ready' ping 응답 후 wasm 미초기화 상태에서 호출되어 __wbindgen_malloc undefined 또는 timeout 발생 #522` 명시 — 이슈 자동 close 트리거
  4. 별도 fork branch (`contrib/fix-iframe-race-condition`) — 본 사이클 패턴 정합
  5. `await initPromise` 단일 패턴 — 분기 없는 정합한 룰 (메모리 `feedback_rule_not_heuristic` 정합)

컨트리뷰터께 부탁드리는 사항 — 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
git checkout devel
git pull --ff-only upstream devel
git push origin devel

새 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 의 본질을 정확히 식별하셨습니다.

@edwardkim edwardkim closed this May 4, 2026
edwardkim added a commit that referenced this pull request May 4, 2026
- mydocs/pr/pr_581_report.md → archives/

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
edwardkim added a commit that referenced this pull request May 4, 2026
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>
edwardkim added a commit that referenced this pull request May 4, 2026
…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 시 명시).
edwardkim added a commit that referenced this pull request May 4, 2026
- 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 항목 추가
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants