Skip to content

Commit 58a5682

Browse files
committed
Handle EINTR.
1 parent 1ed954e commit 58a5682

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

vfs/os_darwin.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ func osSync(file *os.File, fullsync, _ /*dataonly*/ bool) error {
2727
if fullsync {
2828
return file.Sync()
2929
}
30-
return unix.Fsync(int(file.Fd()))
30+
for {
31+
err := unix.Fsync(int(file.Fd()))
32+
if err != unix.EINTR {
33+
return err
34+
}
35+
}
3136
}
3237

3338
func osAllocate(file *os.File, size int64) error {

vfs/os_linux.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package vfs
44

55
import (
6+
"io"
67
"os"
78
"time"
89

@@ -11,14 +12,36 @@ import (
1112

1213
func osSync(file *os.File, _ /*fullsync*/, _ /*dataonly*/ bool) error {
1314
// SQLite trusts Linux's fdatasync for all fsync's.
14-
return unix.Fdatasync(int(file.Fd()))
15+
for {
16+
err := unix.Fdatasync(int(file.Fd()))
17+
if err != unix.EINTR {
18+
return err
19+
}
20+
}
1521
}
1622

1723
func osAllocate(file *os.File, size int64) error {
1824
if size == 0 {
1925
return nil
2026
}
21-
return unix.Fallocate(int(file.Fd()), 0, 0, size)
27+
for {
28+
err := unix.Fallocate(int(file.Fd()), 0, 0, size)
29+
if err == unix.EOPNOTSUPP {
30+
break
31+
}
32+
if err != unix.EINTR {
33+
return err
34+
}
35+
}
36+
off, err := file.Seek(0, io.SeekEnd)
37+
if err != nil {
38+
return err
39+
}
40+
if size <= off {
41+
return nil
42+
}
43+
return file.Truncate(size)
44+
2245
}
2346

2447
func osReadLock(file *os.File, start, len int64, timeout time.Duration) _ErrorCode {

vfs/tests/mptest/mptest_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"github.com/tetratelabs/wazero"
2020
"github.com/tetratelabs/wazero/api"
21-
"github.com/tetratelabs/wazero/experimental"
2221
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
2322

2423
"github.com/ncruces/go-sqlite3/internal/util"
@@ -39,9 +38,7 @@ var (
3938

4039
func TestMain(m *testing.M) {
4140
ctx := context.Background()
42-
cfg := wazero.NewRuntimeConfig().
43-
WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads).
44-
WithMemoryLimitPages(512)
41+
cfg := wazero.NewRuntimeConfig().WithMemoryLimitPages(512)
4542
rt = wazero.NewRuntimeWithConfig(ctx, cfg)
4643
wasi_snapshot_preview1.MustInstantiate(ctx, rt)
4744
env := vfs.ExportHostFunctions(rt.NewHostModuleBuilder("env"))

vfs/tests/speedtest1/speedtest1_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"testing"
1616

1717
"github.com/tetratelabs/wazero"
18-
"github.com/tetratelabs/wazero/api"
19-
"github.com/tetratelabs/wazero/experimental"
2018
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
2119

2220
"github.com/ncruces/go-sqlite3/internal/util"
@@ -37,9 +35,7 @@ func TestMain(m *testing.M) {
3735
initFlags()
3836

3937
ctx := context.Background()
40-
cfg := wazero.NewRuntimeConfig().
41-
WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads).
42-
WithMemoryLimitPages(512)
38+
cfg := wazero.NewRuntimeConfig().WithMemoryLimitPages(512)
4339
rt = wazero.NewRuntimeWithConfig(ctx, cfg)
4440
wasi_snapshot_preview1.MustInstantiate(ctx, rt)
4541
env := vfs.ExportHostFunctions(rt.NewHostModuleBuilder("env"))

0 commit comments

Comments
 (0)