From 19b98393a63e0966d5b803f02b55981d3f0fd49c Mon Sep 17 00:00:00 2001 From: Li Jie Date: Fri, 11 Apr 2025 17:14:26 +0800 Subject: [PATCH] TODO: defer workaround, should remove after fix --- runtime/internal/lib/io/pipe.go | 4 +++- runtime/internal/lib/sync/map.go | 3 ++- runtime/internal/lib/syscall/env_unix.go | 3 ++- runtime/internal/lib/time/zoneinfo_read.go | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/runtime/internal/lib/io/pipe.go b/runtime/internal/lib/io/pipe.go index b3ca0570..3a7b338c 100644 --- a/runtime/internal/lib/io/pipe.go +++ b/runtime/internal/lib/io/pipe.go @@ -80,7 +80,7 @@ func (p *pipe) write(b []byte) (n int, err error) { return 0, p.writeCloseError() default: p.wrMu.Lock() - defer p.wrMu.Unlock() + //TODO(lijie): workaround for defer crash on wasm } for once := true; once || len(b) > 0; once = false { @@ -90,9 +90,11 @@ func (p *pipe) write(b []byte) (n int, err error) { b = b[nw:] n += nw case <-p.done: + p.wrMu.Unlock() return n, p.writeCloseError() } } + p.wrMu.Unlock() return n, nil } diff --git a/runtime/internal/lib/sync/map.go b/runtime/internal/lib/sync/map.go index e8ccf58b..cb7e9d4c 100644 --- a/runtime/internal/lib/sync/map.go +++ b/runtime/internal/lib/sync/map.go @@ -380,7 +380,7 @@ func (m *Map) CompareAndSwap(key, old, new any) bool { } m.mu.Lock() - defer m.mu.Unlock() + //TODO(lijie): workaround for defer crash on wasm read = m.loadReadOnly() swapped := false if e, ok := read.m[key]; ok { @@ -395,6 +395,7 @@ func (m *Map) CompareAndSwap(key, old, new any) bool { // more efficient steady state. m.missLocked() } + m.mu.Unlock() return swapped } diff --git a/runtime/internal/lib/syscall/env_unix.go b/runtime/internal/lib/syscall/env_unix.go index b9e8481e..a9024352 100644 --- a/runtime/internal/lib/syscall/env_unix.go +++ b/runtime/internal/lib/syscall/env_unix.go @@ -163,12 +163,13 @@ func Clearenv() { func Environ() []string { envOnce.Do(copyenv) envLock.RLock() - defer envLock.RUnlock() + //TODO(lijie): workaround for defer crash on wasm a := make([]string, 0, len(envs)) for _, env := range envs { if env != "" { a = append(a, env) } } + envLock.RUnlock() return a } diff --git a/runtime/internal/lib/time/zoneinfo_read.go b/runtime/internal/lib/time/zoneinfo_read.go index b9f5eef0..08415f67 100644 --- a/runtime/internal/lib/time/zoneinfo_read.go +++ b/runtime/internal/lib/time/zoneinfo_read.go @@ -577,7 +577,7 @@ func readFile(name string) ([]byte, error) { if err != nil { return nil, err } - defer closefd(f) + //TODO(lijie): workaround for defer crash on wasm var ( buf [4096]byte ret []byte @@ -592,9 +592,11 @@ func readFile(name string) ([]byte, error) { break } if len(ret) > maxFileSize { + closefd(f) return nil, fileSizeError(name) } } + closefd(f) return ret, err }