Y
Y
Yuri Kovlenko2016-07-20 16:21:29
go
Yuri Kovlenko, 2016-07-20 16:21:29

Cause of error when executing GO script (go-curl)?

It is necessary to make a request to several pages through multi_curl, and then process the received data in a function. There is a code (example):

package main

import (
    "fmt"
    "time"
    curl "github.com/golang-basic/go-curl"
)

func callback(ptr []byte, userdata interface{}) bool {
    fmt.Printf("Size: %v\n", len(ptr))
    return true
}

func main() {
    mc := curl.MultiInit()

    url := []string{
        "http://api.sypexgeo.net/json/12.34.56.78",
        "http://api.sypexgeo.net/json/123.45.67.89",
    }

    for _, u := range url {
        easy := curl.EasyInit()

        easy.Setopt(curl.OPT_URL, u)
        easy.Setopt(curl.OPT_FOLLOWLOCATION, 1)
        easy.Setopt(curl.OPT_WRITEFUNCTION, callback)

        mc.AddHandle(easy)
    }

    defer mc.Cleanup()

    for {
        nRunning, _ := mc.Perform()

        if nRunning == 0 {
            fmt.Println("exit")
            break
        }

        time.Sleep(time.Millisecond * 100)
    }
}

When it is executed, an error occurs:
unexpected fault address 0xc20803a038
fatal error: fault
[signal 0xb code=0x2 addr=0xc20803a038 pc=0xc20803a038]

goroutine 16 [running]:
runtime.throw(0x7846a2)
  /usr/lib/go/src/pkg/runtime/panic.c:520 +0x69 fp=0x7f748a417f00 sp=0x7f748a417ee8
runtime: unexpected return pc for runtime.sigpanic called from 0xc20803a038
runtime.sigpanic()
  /usr/lib/go/src/pkg/runtime/os_linux.c:240 +0x13f fp=0x7f748a417f18 sp=0x7f748a417f00
created by _rt0_go
  /usr/lib/go/src/pkg/runtime/asm_amd64.s:97 +0x120

goroutine 19 [finalizer wait]:
runtime.park(0x4160e0, 0x793518, 0x787189)
  /usr/lib/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x793518, 0x787189)
  /usr/lib/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
  /usr/lib/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
  /usr/lib/go/src/pkg/runtime/proc.c:1445

goroutine 17 [syscall]:
runtime.goexit()
  /usr/lib/go/src/pkg/runtime/proc.c:1445
exit status 2

What could be wrong?
PS> Unfortunately, the standard net/http is not suitable due to some features of the task.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Kovlenko, 2016-07-21
@BaronAleks

As noted in the comments to the question, the error occurred when accessing the same object from multiple threads. As a result, I abandoned the use of go-curl and rewrote the module via net/http using goroutine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question