Skip to content

syscall: accept(2) syscall blocked on Android, use accept4(2) instead #45767

@jack5105

Description

@jack5105

What version of Go are you using (go version)?

go version go1.15.11 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GO111MODULE="on"
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build729311614=/tmp/go-build -gno-record-gcc-switches"

What did you do?

import (
	"net"
	"strconv"
	"strings"
	"time"
)

type NetDemoApi struct {
}

func (nda *NetDemoApi) Run(serverAddr string, localPort int) error {
	var localIP string
	if conn, e := net.DialTimeout("tcp4", serverAddr, 3*time.Second); e == nil {
		localIP = conn.LocalAddr().String()
		conn.Close()
		if idx := strings.LastIndexByte(localIP, ':'); idx >= 0 {
			localIP = localIP[:idx]
		}
	} else
	{
		return e
	}

	addr := net.JoinHostPort(localIP, strconv.Itoa(localPort))
	ln, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	go func() {
		_, err := ln.Accept()
		if err != nil {
			return
		}
	}()

	time.Sleep(time.Second * 60)

	return nil
}

I use gomobile to build aar with above code, then use this aar in app. When app running, I turn off the wifi, then app crash.

2021-04-26 14:26:16.276 30002-30002/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: Build fingerprint: 'HUAWEI/EML-AL00/HWEML:10/HUAWEIEML-AL00/10.0.0.156C00:user/release-keys'
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: Revision: '0'
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: ABI: 'arm64'
2021-04-26 14:26:16.277 1257-4257/system_process I/chatty: uid=1000(system) Binder:1257_13 expire 1 line
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: SYSVMTYPE: Maple
    APPVMTYPE: Art
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: Timestamp: 2021-04-26 14:26:16+0800
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: pid: 29812, tid: 29872, name: Thread-2  >>> org.golang.example.android <<<
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: uid: 10001
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: signal 31 (SIGSYS), code 1 (SYS_SECCOMP), fault addr --------
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: Cause: seccomp prevented call to disallowed arm64 system call 202
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x0  0000000000000056  x1  000000400002c498  x2  000000400002c478  x3  0000000000000000
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x4  0000000000000000  x5  0000000000000000  x6  0000000000000001  x7  00000000016944e8
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x8  00000000000000ca  x9  000ee6b280000000  x10 000000000001abdc  x11 000000000f92b524
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x12 0000000000000016  x13 0000000060865d08  x14 0001dac7eb968cd3  x15 0000088991354fbd
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x16 000000774d609ac8  x17 0000000000000000  x18 000000774703c000  x19 0000000000000030
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x20 000000400002c4f8  x21 000000774d869cc0  x22 0000000000000001  x23 000000774d8995b5
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x24 000000774d8691b0  x25 0000000000000018  x26 000000774d7c0120  x27 0000000000000000
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x28 0000004000000180  x29 0000000000000000
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     sp  000000400002c3d0  lr  000000774d6f7ac8  pc  000000774d6f7ae8
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: backtrace:
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:       #00 pc 00000000000e9ae8  /data/app/org.golang.example.android-mzk5Nz7vrkXGh6877_slNQ==/lib/arm64/libgojni.so

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.mobileAndroid, iOS, and x/mobile

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions