From 58a5682084176ee22ec090f995e2a6c5b75b8ed2 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Tue, 11 Mar 2025 12:07:14 +0000 Subject: [PATCH] Handle EINTR. --- vfs/os_darwin.go | 7 ++++++- vfs/os_linux.go | 27 +++++++++++++++++++++++-- vfs/tests/mptest/mptest_test.go | 5 +---- vfs/tests/speedtest1/speedtest1_test.go | 6 +----- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/vfs/os_darwin.go b/vfs/os_darwin.go index 07de7c3..e1e3536 100644 --- a/vfs/os_darwin.go +++ b/vfs/os_darwin.go @@ -27,7 +27,12 @@ func osSync(file *os.File, fullsync, _ /*dataonly*/ bool) error { if fullsync { return file.Sync() } - return unix.Fsync(int(file.Fd())) + for { + err := unix.Fsync(int(file.Fd())) + if err != unix.EINTR { + return err + } + } } func osAllocate(file *os.File, size int64) error { diff --git a/vfs/os_linux.go b/vfs/os_linux.go index 6199c7b..4bc461b 100644 --- a/vfs/os_linux.go +++ b/vfs/os_linux.go @@ -3,6 +3,7 @@ package vfs import ( + "io" "os" "time" @@ -11,14 +12,36 @@ import ( func osSync(file *os.File, _ /*fullsync*/, _ /*dataonly*/ bool) error { // SQLite trusts Linux's fdatasync for all fsync's. - return unix.Fdatasync(int(file.Fd())) + for { + err := unix.Fdatasync(int(file.Fd())) + if err != unix.EINTR { + return err + } + } } func osAllocate(file *os.File, size int64) error { if size == 0 { return nil } - return unix.Fallocate(int(file.Fd()), 0, 0, size) + for { + err := unix.Fallocate(int(file.Fd()), 0, 0, size) + if err == unix.EOPNOTSUPP { + break + } + if err != unix.EINTR { + return err + } + } + off, err := file.Seek(0, io.SeekEnd) + if err != nil { + return err + } + if size <= off { + return nil + } + return file.Truncate(size) + } func osReadLock(file *os.File, start, len int64, timeout time.Duration) _ErrorCode { diff --git a/vfs/tests/mptest/mptest_test.go b/vfs/tests/mptest/mptest_test.go index ad27ab6..7b6aa9a 100644 --- a/vfs/tests/mptest/mptest_test.go +++ b/vfs/tests/mptest/mptest_test.go @@ -18,7 +18,6 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" - "github.com/tetratelabs/wazero/experimental" "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/ncruces/go-sqlite3/internal/util" @@ -39,9 +38,7 @@ var ( func TestMain(m *testing.M) { ctx := context.Background() - cfg := wazero.NewRuntimeConfig(). - WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads). - WithMemoryLimitPages(512) + cfg := wazero.NewRuntimeConfig().WithMemoryLimitPages(512) rt = wazero.NewRuntimeWithConfig(ctx, cfg) wasi_snapshot_preview1.MustInstantiate(ctx, rt) env := vfs.ExportHostFunctions(rt.NewHostModuleBuilder("env")) diff --git a/vfs/tests/speedtest1/speedtest1_test.go b/vfs/tests/speedtest1/speedtest1_test.go index 8416d60..f733aeb 100644 --- a/vfs/tests/speedtest1/speedtest1_test.go +++ b/vfs/tests/speedtest1/speedtest1_test.go @@ -15,8 +15,6 @@ import ( "testing" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/api" - "github.com/tetratelabs/wazero/experimental" "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/ncruces/go-sqlite3/internal/util" @@ -37,9 +35,7 @@ func TestMain(m *testing.M) { initFlags() ctx := context.Background() - cfg := wazero.NewRuntimeConfig(). - WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads). - WithMemoryLimitPages(512) + cfg := wazero.NewRuntimeConfig().WithMemoryLimitPages(512) rt = wazero.NewRuntimeWithConfig(ctx, cfg) wasi_snapshot_preview1.MustInstantiate(ctx, rt) env := vfs.ExportHostFunctions(rt.NewHostModuleBuilder("env"))