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

x/mobile: https(ioutils) crashes the app #9416

Closed
chiaen opened this issue Dec 22, 2014 · 5 comments

Comments

Projects
None yet
5 participants
@chiaen
Copy link

commented Dec 22, 2014

I have a cache service runs on android(as a executable). It forwards the https requests and caches the results for apps on devices. After go1.4, I try to integrate this component as native function to cope more efficiently with Android environment. But thing goes weird when I tried to initiate a https request using native call, the call would crash the app. I traced the problem down and the root cause appears to locate at bottom level where certificates are loaded using go ioutils.

What version of Go are you using (go version)?
go1.4

What operating system and processor architecture are you using?
android 4.4.2

What did you do?

in modified golang.org/x/mobile/example/libhello
calling go function

func Test() {
    req, err := http.NewRequest("GET", "https://www.example.com", nil)
    if err != nil {
        log.Printf("error: %v", err)
    }
    client := &http.Client{}
    resp, err := client.Do(req)
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        log.Printf("error: %v", err)
    }
    log.Printf(string(body))
}

with the following

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

What did you expect to see?

Correctly return html body

What did you see instead?

The call crashes the app

@dopsilva

This comment has been minimized.

Copy link

commented Dec 22, 2014

To resolve the hostname (www.example.com) you need the permission ACCESS_NETWORK_STATE.

Try add this permission to the manifest

@chiaen

This comment has been minimized.

Copy link
Author

commented Dec 22, 2014

Thanks, but I still get app crashes after adding the permission.

I tracked down the crash to
/go/src/crypto/x509/root_unix.go:44

    for _, directory := range certDirectories {                                                                                                               
        fis, err := ioutil.ReadDir(directory)
        if err != nil {
            continue
        }
        rootsAdded := false
        for _, fi := range fis {
            data, err := ioutil.ReadFile(directory + "/" + fi.Name())
            if err == nil && roots.AppendCertsFromPEM(data) {
                rootsAdded = true
            }
        }
        if rootsAdded {
            systemRoots = roots
            return
        }
    }

I was able to isolate the problem by using ioutil to read directory. And the file number in the directory is related to crash. That is, more files in directory, the more likely the app crash. It might be the limited memory size in managed Android environment that causing the problem.

@crawshaw

This comment has been minimized.

Copy link
Contributor

commented Dec 22, 2014

How many files are you seeing in the directory?

Can you show us the error you are seeing on crash? (You may not see an error message if you are using 1.4 release. If so, could you sync after bee8ae1.)

@crawshaw crawshaw self-assigned this Dec 22, 2014

@chiaen

This comment has been minimized.

Copy link
Author

commented Dec 23, 2014

I used /system/etc/security/cacerts, the directory contains ca which is 5KB average. And the app would crash after put 70 ca in the directory.

And I got the error log after sync to your patch

I/Go      (32741): app.Run
I/go/Seq  (32741): loaded go/Seq
I/Go      (32741): Runtime started
I/GoLog   (32741): Hello, world!
D/libc    (32741): [NET] getaddrinfo+,hn 15(0x7777772e657861),sn(),family 0,flags 2
D/libc    (32741): [NET] getaddrinfo-, 1
D/libc    (32741): [NET] getaddrinfo_proxy+
E/Go      (32741): SIGABRT: abort
E/Go      (32741): PC=0x789af1dc
E/Go      (32741): goroutine 4 [syscall]:
E/Go      (32741): syscall.Syscall(0x6, 0x1, 0x0, 0x0, 0x78964bb4, 0x88eb23fc, 0x78970dac)
E/Go      (32741):  /go/src/syscall/asm_linux_arm.s:17 +0x8 fp=0x88ec7734 sp=0x88ec7730
E/Go      (32741): syscall.Close(0x1, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/zsyscall_linux_arm.go:280 +0x4c fp=0x88ec7758 sp=0x88ec7734
E/Go      (32741): os.(*file).close(0x88ee60e0, 0x0, 0x0)
E/Go      (32741):  /go/src/os/file_unix.go:106 +0x58 fp=0x88ec7794 sp=0x88ec7758
E/Go      (32741): runtime.call16(0x78bf98d0, 0x88ede450, 0x10, 0x10)
E/Go      (32741):  /go/src/runtime/asm_arm.s:406 +0x70 fp=0x88ec77a8 sp=0x88ec7794
E/Go      (32741): runtime.runfinq()
E/Go      (32741):  /go/src/runtime/malloc.go:769 +0x298 fp=0x88ec77ec sp=0x88ec77a8
E/Go      (32741): runtime.goexit()
E/Go      (32741):  /go/src/runtime/asm_arm.s:1322 +0x4 fp=0x88ec77ec sp=0x88ec77ec
E/Go      (32741): created by runtime.createfing
E/Go      (32741):  /go/src/runtime/malloc.go:707 +0x6c
E/Go      (32741): goroutine 1 [chan receive, locked to thread]:
E/Go      (32741): golang.org/x/mobile/app.run(0x0, 0x0)
E/Go      (32741):  /src/golang.org/x/mobile/app/android.go:252 +0x168
E/Go      (32741): golang.org/x/mobile/app.Run(0x0, 0x0)
E/Go      (32741):  /src/golang.org/x/mobile/app/app.go:18 +0x2c
E/Go      (32741): main.main()
E/Go      (32741):  /src/golang.org/x/mobile/example/libhello/main.go:19 +0x3c
E/Go      (32741): goroutine 17 [select, locked to thread]:
E/Go      (32741): net/http.(*Transport).getConn(0x88ee8310, 0x88ee83f0, 0x0, 0x78bbb378, 0x5, 0x88ee6a60, 0x13, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/transport.go:525 +0x508
E/Go      (32741): net/http.(*Transport).RoundTrip(0x88ee8310, 0x88ee83f0, 0x17, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/transport.go:228 +0x390
E/Go      (32741): net/http.send(0x88ee83f0, 0xa8ec5b68, 0x88ee8310, 0x17, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/client.go:219 +0x3f0
E/Go      (32741): net/http.(*Client).send(0x88ee6a20, 0x88ee83f0, 0x17, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/client.go:142 +0x138
E/Go      (32741): net/http.(*Client).doFollowingRedirects(0x88ee6a20, 0x88ee83f0, 0x78bf98bc, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/client.go:410 +0x9f0
E/Go      (32741): net/http.(*Client).Do(0x88ee6a20, 0x88ee83f0, 0x78bbb378, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/client.go:174 +0xac
E/Go      (32741): golang.org/x/mobile/example/libhello/hi.TestGet()
E/Go      (32741):  /src/golang.org/x/mobile/example/libhello/hi/hi.go:29 +0x154
E/Go      (32741): golang.org/x/mobile/example/libhello/hi.Hello(0x88ede440, 0x5)
E/Go      (32741):  /src/golang.org/x/mobile/example/libhello/hi/hi.go:68 +0xd8
E/Go      (32741): golang.org/x/mobile/example/libhello/hi/go_hi.proxy_Hello(0x88ede430, 0x88ede420)
E/Go      (32741):  /src/golang.org/x/mobile/example/libhello/hi/go_hi/go_hi.go:14 +0x48
E/Go      (32741): golang.org/x/mobile/bind/java.Send(0x72848230, 0x2, 0x1, 0x728481d0, 0xe, 0x72848218, 0x72848220)
E/Go      (32741):  /src/golang.org/x/mobile/bind/java/seq_android.go:35 +0x12c
E/Go      (32741): goroutine 5 [syscall]:
E/Go      (32741): syscall.Syscall(0x3, 0x38, 0x88ee4400, 0x400, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/asm_linux_arm.s:17 +0x8
E/Go      (32741): syscall.read(0x38, 0x88ee4400, 0x400, 0x400, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/zsyscall_linux_arm.go:867 +0x80
E/Go      (32741): syscall.Read(0x38, 0x88ee4400, 0x400, 0x400, 0x88ee4400, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/syscall_unix.go:136 +0x54
E/Go      (32741): os.(*File).read(0x88ebc2e0, 0x88ee4400, 0x400, 0x400, 0x1, 0x0, 0x0)
E/Go      (32741):  /go/src/os/file_unix.go:191 +0x5c
E/Go      (32741): os.(*File).Read(0x88ebc2e0, 0x88ee4400, 0x400, 0x400, 0x78b3e440, 0x0, 0x0)
E/Go      (32741):  /go/src/os/file.go:95 +0x80
E/Go      (32741): bufio.(*Reader).fill(0x88eda1e0)
E/Go      (32741):  /go/src/bufio/bufio.go:97 +0x1d8
E/Go      (32741): bufio.(*Reader).ReadSlice(0x88eda1e0, 0xa8ec5a0a, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/bufio/bufio.go:295 +0x2a4
E/Go      (32741): bufio.(*Reader).ReadLine(0x88eda1e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/bufio/bufio.go:324 +0x70
E/Go      (32741): golang.org/x/mobile/app.lineLog(0x88ebc2e0, 0x6)
E/Go      (32741):  /src/golang.org/x/mobile/app/stdio_android.go:45 +0x84
E/Go      (32741): created by golang.org/x/mobile/app.init·1
E/Go      (32741):  /src/golang.org/x/mobile/app/stdio_android.go:69 +0x110
E/Go      (32741): goroutine 6 [syscall]:
E/Go      (32741): syscall.Syscall(0x3, 0x3a, 0x88ee4800, 0x400, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/asm_linux_arm.s:17 +0x8
E/Go      (32741): syscall.read(0x3a, 0x88ee4800, 0x400, 0x400, 0x48c44801, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/zsyscall_linux_arm.go:867 +0x80
E/Go      (32741): syscall.Read(0x3a, 0x88ee4800, 0x400, 0x400, 0x88ee4800, 0x0, 0x0)
E/Go      (32741):  /go/src/syscall/syscall_unix.go:136 +0x54
E/Go      (32741): os.(*File).read(0x88ebc2f0, 0x88ee4800, 0x400, 0x400, 0x1, 0x0, 0x0)
E/Go      (32741):  /go/src/os/file_unix.go:191 +0x5c
E/Go      (32741): os.(*File).Read(0x88ebc2f0, 0x88ee4800, 0x400, 0x400, 0x78b3e440, 0x0, 0x0)
E/Go      (32741):  /go/src/os/file.go:95 +0x80
E/Go      (32741): bufio.(*Reader).fill(0x88eda210)
E/Go      (32741):  /go/src/bufio/bufio.go:97 +0x1d8
E/Go      (32741): bufio.(*Reader).ReadSlice(0x88eda210, 0xa8ec5a0a, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/bufio/bufio.go:295 +0x2a4
E/Go      (32741): bufio.(*Reader).ReadLine(0x88eda210, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/bufio/bufio.go:324 +0x70
E/Go      (32741): golang.org/x/mobile/app.lineLog(0x88ebc2f0, 0x4)
E/Go      (32741):  /src/golang.org/x/mobile/app/stdio_android.go:45 +0x84
E/Go      (32741): created by golang.org/x/mobile/app.init·1
E/Go      (32741):  /src/golang.org/x/mobile/app/stdio_android.go:76 +0x1a8
E/Go      (32741): goroutine 18 [semacquire, locked to thread]:
E/Go      (32741): sync.(*Cond).Wait(0x78ca20e8)
E/Go      (32741):  /go/src/sync/cond.go:62 +0xcc
E/Go      (32741): golang.org/x/mobile/bind/java.Recv(0x77d8b9f8, 0x77d8ba00, 0x7265c270, 0x6dd39490, 0x77babe50)
E/Go      (32741):  /src/golang.org/x/mobile/bind/java/seq_android.go:107 +0x68
E/Go      (32741): goroutine 7 [select]:
E/Go      (32741): net.lookupIPDeadline(0x88ee6a60, 0xf, 0xcc2ac4e2, 0xe, 0x33acbf00, 0x78ca2118, 0x0, 0x0, 0x0, 0x0, ...)
E/Go      (32741):  /go/src/net/lookup.go:82 +0x5c8
E/Go      (32741): net.resolveInternetAddr(0x78b99f48, 0x3, 0x88ee6a60, 0x13, 0xcc2ac4e2, 0xe, 0x33acbf00, 0x78ca2118, 0x0, 0x0, ...)
E/Go      (32741):  /go/src/net/ipsock.go:285 +0x368
E/Go      (32741): net.resolveAddr(0x78b9cf78, 0x4, 0x78b99f48, 0x3, 0x88ee6a60, 0x13, 0xcc2ac4e2, 0xe, 0x33acbf00, 0x78ca2118, ...)
E/Go      (32741):  /go/src/net/dial.go:110 +0x2b4
E/Go      (32741): net.(*Dialer).Dial(0x88eda1b0, 0x78b99f48, 0x3, 0x88ee6a60, 0x13, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/dial.go:158 +0xc8
E/Go      (32741): net.*Dialer.Dial·fm(0x78b99f48, 0x3, 0x88ee6a60, 0x13, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/transport.go:38 +0x64
E/Go      (32741): net/http.(*Transport).dial(0x88ee8310, 0x78b99f48, 0x3, 0x88ee6a60, 0x13, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/transport.go:479 +0x78
E/Go      (32741): net/http.(*Transport).dialConn(0x88ee8310, 0x0, 0x78bbb378, 0x5, 0x88ee6a60, 0x13, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/http/transport.go:645 +0x1350
E/Go      (32741): net/http.func·019()
E/Go      (32741):  /go/src/net/http/transport.go:520 +0x40
E/Go      (32741): created by net/http.(*Transport).getConn
E/Go      (32741):  /go/src/net/http/transport.go:522 +0x2ec
E/Go      (32741): goroutine 9 [syscall, locked to thread]:
E/Go      (32741): net._C2func_getaddrinfo(0x77d8b250, 0x0, 0x88ec4ed8, 0x88ec4e80, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/:22 +0x58
E/Go      (32741): net.cgoLookupIPCNAME(0x88ee6a60, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/cgo_unix.go:96 +0x17c
E/Go      (32741): net.cgoLookupIP(0x88ee6a60, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/cgo_unix.go:148 +0x58
E/Go      (32741): net.lookupIP(0x88ee6a60, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/lookup_unix.go:64 +0x50
E/Go      (32741): net.func·026(0x0, 0x0, 0x0, 0x0)
E/Go      (32741):  /go/src/net/lookup.go:79 +0x50
E/Go      (32741): net.(*singleflight).doCall(0x78ca1e90, 0x88ed8400, 0x88ee6a60, 0xf, 0x88ebc300)
E/Go      (32741):  /go/src/net/singleflight.go:91 +0x24
E/Go      (32741): created by net.(*singleflight).DoChan
E/Go      (32741):  /go/src/net/singleflight.go:84 +0x3c0
E/Go      (32741): goroutine 19 [syscall, locked to thread]:
E/Go      (32741): runtime.goexit()
E/Go      (32741):  /go/src/runtime/asm_arm.s:1322 +0x4
E/Go      (32741): trap    0x0
E/Go      (32741): error   0x0
E/Go      (32741): oldmask 0x0
E/Go      (32741): r0      0xbadfd
E/Go      (32741): r1      0x0
E/Go      (32741): r2      0x0
E/Go      (32741): r3      0x0
E/Go      (32741): r4      0x0
E/Go      (32741): r5      0x0
E/Go      (32741): r6      0x88eb23c0
E/Go      (32741): r7      0x6
E/Go      (32741): r8      0x88ede460
E/Go      (32741): r9      0xa95b6000
E/Go      (32741): r10     0x88eb23c0
E/Go      (32741): fp      0xffffffff
E/Go      (32741): ip      0x88ede45d
E/Go      (32741): sp      0x88ec7730
E/Go      (32741): lr      0x789a05a4
E/Go      (32741): pc      0x789af1dc
E/Go      (32741): cpsr    0x60070010
E/Go      (32741): fault   0x0
I/ActivityManager(  970): Recipient 32741
I/ActivityManager(  970): Process com.example.hello (pid 32741) has died.

@hyangah hyangah added repo-mobile and removed repo-mobile labels Dec 23, 2014

@chiaen

This comment has been minimized.

Copy link
Author

commented Jan 7, 2015

After cross testing on multiple devices, this issue only appears on devices with proprietary pre-release rom. More likely be a issue related to our customisation. Thanks @dopsilva @crawshaw

@chiaen chiaen closed this Jan 7, 2015

@mikioh mikioh changed the title mobile: https(ioutils) crashes the app x/mobile: https(ioutils) crashes the app Aug 5, 2015

@golang golang locked and limited conversation to collaborators Aug 5, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.