]> Cypherpunks repositories - gostls13.git/commit
syscall: on wasm, do not use typed array asynchronously
authorRichard Musiol <mail@richard-musiol.de>
Tue, 30 Apr 2019 17:16:23 +0000 (19:16 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 30 Apr 2019 22:41:20 +0000 (22:41 +0000)
commit6505b4853196a172cfe4dd161072dfb8afb6b0be
tree01aab7e4e269aedac53ef9b20b3dc1e4068d9868
parent65b89c3542fb3d36632e404f672b41f111b8b60a
syscall: on wasm, do not use typed array asynchronously

The underlying buffer of a typed array becomes invalid as soon as we
grow the WebAssembly memory, which can happen at any time while Go code
runs. This is a known limitation, see https://golang.org/cl/155778.

As a consequence, using a typed array with one of the asynchronous
read/write operations of Node.js' fs module is dangerous, since it may
become invalid while the asynchronous operation has not finished yet.
The result of this situation is most likely undefined.

I am not aware of any nice solution to this issue, so this change adds
a workaround of using an additional typed array which is not backed by
WebAssembly memory and copying the bytes between the two typed arrays.

Maybe WebAssembly will come up with a better solution in the future.

Fixes #31702.

Change-Id: Iafc2a0fa03c81db414520bd45a1a17c00080b61e
Reviewed-on: https://go-review.googlesource.com/c/go/+/174304
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/syscall/fs_js.go