geziyor/geziyor

cannot create context from nil parent

TheUltimateCookie opened this issue · 2 comments

I'm pretty new to go so I'm not exactly sure why this is happening. The program is pretty is simple

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"

	"github.com/geziyor/geziyor"
	"github.com/geziyor/geziyor/client"
)

func main() {
	var result map[string]interface{}
	resp, err := http.Get("http://localhost:9222/json/version")
	if err != nil {
		log.Fatal(err)
	}
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		log.Fatal(err)
	}

	geziyor.NewGeziyor(&geziyor.Options{
		StartRequestsFunc: func(g *geziyor.Geziyor) {
			g.GetRendered("https://growth.cx", g.Opt.ParseFunc)
		},
		ParseFunc: func(g *geziyor.Geziyor, r *client.Response) {
			fmt.Println(string(r.Body))
		},
		BrowserEndpoint:   result["webSocketDebuggerUrl"].(string),
		RobotsTxtDisabled: true,
	}).Start()
}

I created a Dockerfile like this

FROM golang:1.15-buster as builder

WORKDIR /app

COPY go.* ./
RUN go mod download

COPY . ./

RUN go build -v -o server

FROM chromedp/headless-shell:latest

COPY --from=builder /app/server /app/server

CMD ["/app/server"]

When docker exec -it container-name bash and run ./app/server, I get the following error

Scraping Started
cannot create context from nil parent goroutine 42 [running]:
runtime/debug.Stack(0xc000077a78, 0xb3dbe0, 0xd08cd0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9f
github.com/geziyor/geziyor.(*Geziyor).recoverMe(0xc000228fa0)
        /go/pkg/mod/github.com/geziyor/geziyor@v0.0.0-20210530074354-d3bdaf624012/geziyor.go:310 +0x57
panic(0xb3dbe0, 0xd08cd0)
        /usr/local/go/src/runtime/panic.go:969 +0x1b9
context.WithCancel(0x0, 0x0, 0xc00006cc00, 0x0, 0x203000)
        /usr/local/go/src/context/context.go:234 +0x165
github.com/chromedp/chromedp.NewRemoteAllocator(0x0, 0x0, 0xc0000fa5a0, 0x49, 0xd0, 0xd0, 0x203000)
        /go/pkg/mod/github.com/chromedp/chromedp@v0.7.4/allocate.go:505 +0x3f
github.com/geziyor/geziyor/client.(*Client).doRequestChrome(0xc000033f40, 0xc0002a2200, 0x0, 0x0, 0x0)
        /go/pkg/mod/github.com/geziyor/geziyor@v0.0.0-20210530074354-d3bdaf624012/client/client.go:165 +0xd0
github.com/geziyor/geziyor/client.(*Client).DoRequest(0xc000033f40, 0xc0002a2200, 0x0, 0x0, 0x0)
        /go/pkg/mod/github.com/geziyor/geziyor@v0.0.0-20210530074354-d3bdaf624012/client/client.go:84 +0x5c
github.com/geziyor/geziyor.(*Geziyor).do(0xc000228fa0, 0xc0002a2200, 0xc77390)
        /go/pkg/mod/github.com/geziyor/geziyor@v0.0.0-20210530074354-d3bdaf624012/geziyor.go:249 +0x165
created by github.com/geziyor/geziyor.(*Geziyor).Do
        /go/pkg/mod/github.com/geziyor/geziyor@v0.0.0-20210530074354-d3bdaf624012/geziyor.go:231 +0xa8

Scraping Finished

Is this my mistake or something wrong with geziyor?
Please advice

This problem should be fixed with the #29 PR. Could you pull the master and confirm that it fixes the problem

I went to go.mod and upgraded transitive dependencies and direct dependencies. Now it's working.