Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi: add nonblock_test.go from gotip, fix nonblock read on Unix-like #1517

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

evacchi
Copy link
Contributor

@evacchi evacchi commented Jun 13, 2023

Adapt and add the test from Go's WASI test suite nonblock.go for non-blocking I/O (pipes) to our own suite. Go (almost) straight to the syscall layer for read() on supported platforms; i.e., this is currently Unix-only. This also adds the field fd to the struct osFile because apparently f.file.Fd() resets the O_NONBLOCK flag on the fd /o.

Signed-off-by: Edoardo Vacchi evacchi@users.noreply.github.com

Copy link
Collaborator

@achille-roussel achille-roussel left a comment

Choose a reason for hiding this comment

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

👏

@evacchi evacchi marked this pull request as draft June 13, 2023 16:49
@evacchi
Copy link
Contributor Author

evacchi commented Jun 13, 2023

ew, I guess this is a bad case of WorksOnMyMachine™️

@evacchi
Copy link
Contributor Author

evacchi commented Jun 13, 2023

weird, on Linux it does set nonblock = true, but it still blocks on read??
EDIT: so it looks like it does return EAGAIN but then we are going through the Go runtime, which, probably as in the case of sockets (?) gets in the way of actually returning EAGAIN. In fact, the underlying syscall does return EAGAIN.

we can go straight to the syscall; in that case, EAGAIN is returned correctly and the runtime jumps through all the FDs, but apparently all of them have always no data and return EAGAIN. I guess I am going to debug this later/tomorrow.

EDIT2: well sure they had nothing to read, I was redirecting the pipe to screen instead :D so the syscall approach does work... let's see what I can do...

EDIT3: so that's why I had to setNonblock(fd) every time I called f.file.Fd()... 🤣

func (f *File) Fd() uintptr {
	if f == nil {
		return ^(uintptr(0))
	}

	// If we put the file descriptor into nonblocking mode,
	// then set it to blocking mode before we return it,
	// because historically we have always returned a descriptor
	// opened in blocking mode. The File will continue to work,
	// but any blocking operation will tie up a thread.
	if f.nonblock {
		f.pfd.SetBlocking()
	}

@evacchi
Copy link
Contributor Author

evacchi commented Jun 13, 2023

OK I think I found a solution that is more solid; pretty much, again, like for sockets, going almost straight to the syscall layers for platforms that we support for nonblocking I/O (i.e. Unix for now). Probably better to add some specific test case before finalizing this, but this should make the gotip test work everywhere.

@evacchi evacchi changed the title wasi: add nonblock_test.go from gotip wasi: add nonblock_test.go from gotip, fix nonblock read on Unix-like Jun 13, 2023
@evacchi
Copy link
Contributor Author

evacchi commented Jun 13, 2023

ok apparently something I did (maybe the f.fd in place of f.file.Fd()) ? broke Windows. I guess it's a good time to call it a day :D

@evacchi
Copy link
Contributor Author

evacchi commented Jun 13, 2023

Windows is fixed, but it looks like everything else is still broken... I'll investigate tomorrow, unless someone else wants to take over :)

@codefromthecrypt
Copy link
Contributor

Thanks for the focused help on this stuff @evacchi!

@evacchi evacchi marked this pull request as ready for review June 14, 2023 08:12
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
@evacchi
Copy link
Contributor Author

evacchi commented Jun 14, 2023

added tiny test case for readFd (all platforms) and nonblocking f.Read() (non-Windows)

internal/sysfs/file_unix.go Show resolved Hide resolved
internal/sysfs/file_unsupported.go Show resolved Hide resolved
@evacchi
Copy link
Contributor Author

evacchi commented Jun 14, 2023

the timeouts are back, let's try to revert the commit with the build flags and see if it's related

Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@codefromthecrypt codefromthecrypt merged commit b01ba67 into tetratelabs:main Jun 14, 2023
@evacchi evacchi deleted the nonblock-gotip branch June 15, 2023 07:27
evacchi added a commit to evacchi/wazero that referenced this pull request Jun 15, 2023
…tetratelabs#1517)

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
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.

4 participants