git: 41e4cf7d809d - main - lang/go119: Backport upstream fix for /dev/fuse polling issue

From: Dmitri Goutnik <dmgk_at_FreeBSD.org>
Date: Tue, 09 Aug 2022 17:29:17 UTC
The branch main has been updated by dmgk:

URL: https://cgit.FreeBSD.org/ports/commit/?id=41e4cf7d809db0be86d7aced3107ba9eec12a4bb

commit 41e4cf7d809db0be86d7aced3107ba9eec12a4bb
Author:     Dmitri Goutnik <dmgk@FreeBSD.org>
AuthorDate: 2022-08-09 17:14:18 +0000
Commit:     Dmitri Goutnik <dmgk@FreeBSD.org>
CommitDate: 2022-08-09 17:28:23 +0000

    lang/go119: Backport upstream fix for /dev/fuse polling issue
    
    This a backport of Go CL 420334.
    
    PR:             258056
    Obtained from:  https://go-review.googlesource.com/c/go/+/420334/
---
 lang/go119/Makefile                         |  2 +-
 lang/go119/files/patch-src_os_file__unix.go | 55 +++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/lang/go119/Makefile b/lang/go119/Makefile
index ea9aa3fde1c2..3a2fb89410dc 100644
--- a/lang/go119/Makefile
+++ b/lang/go119/Makefile
@@ -1,6 +1,6 @@
 DISTVERSION=	1.19
 # Always set PORTREVISION explicitly as otherwise they are inherited from lang/go-devel
-PORTREVISION=	0
+PORTREVISION=	1
 MASTER_SITES=	https://golang.org/dl/ \
 		https://github.com/dmgk/go-bootstrap/releases/download/${BOOTSTRAP_TAG}/:bootstrap \
 		LOCAL/dmgk:bootstrap
diff --git a/lang/go119/files/patch-src_os_file__unix.go b/lang/go119/files/patch-src_os_file__unix.go
new file mode 100644
index 000000000000..3f53fce01948
--- /dev/null
+++ b/lang/go119/files/patch-src_os_file__unix.go
@@ -0,0 +1,55 @@
+From 21a3e299aad894f744292d8cf1db4120efb3651f Mon Sep 17 00:00:00 2001
+From: Yuval Pavel Zholkover <paulzhol@gmail.com>
+Date: Sat, 30 Jul 2022 20:41:58 +0300
+Subject: [PATCH] os: only add file descriptors which are set to non-blocking mode to the netpoller
+
+Either ones where kind == kindNonBlock or those we've successfully called syscall.SetNonblock() on.
+Restore blocking behavior if we detect an error registering with the netpoller and our flow was
+successful in setting the inital syscall.SetNonblock().
+
+Update #54100
+
+Change-Id: I08934e4107c7fb36c15a7ca23ac880490b4df235
+
+--- src/os/file_unix.go.orig	2022-08-01 22:45:57 UTC
++++ src/os/file_unix.go
+@@ -168,18 +168,28 @@ func newFile(fd uintptr, name string, kind newFileKind
+ 		}
+ 	}
+ 
+-	if err := f.pfd.Init("file", pollable); err != nil {
+-		// An error here indicates a failure to register
+-		// with the netpoll system. That can happen for
+-		// a file descriptor that is not supported by
+-		// epoll/kqueue; for example, disk files on
+-		// Linux systems. We assume that any real error
+-		// will show up in later I/O.
+-	} else if pollable {
+-		// We successfully registered with netpoll, so put
+-		// the file into nonblocking mode.
+-		if err := syscall.SetNonblock(fdi, true); err == nil {
++	clearNonBlock := false
++	if pollable {
++		if kind == kindNonBlock {
+ 			f.nonblock = true
++		} else if err := syscall.SetNonblock(fdi, true); err == nil {
++			f.nonblock = true
++			clearNonBlock = true
++		} else {
++			pollable = false
++		}
++	}
++
++	// An error here indicates a failure to register
++	// with the netpoll system. That can happen for
++	// a file descriptor that is not supported by
++	// epoll/kqueue; for example, disk files on
++	// Linux systems. We assume that any real error
++	// will show up in later I/O.
++	// We do restore the blocking behavior if it was set by us.
++	if pollErr := f.pfd.Init("file", pollable); pollErr != nil && clearNonBlock {
++		if err := syscall.SetNonblock(fdi, false); err == nil {
++			f.nonblock = false
+ 		}
+ 	}
+