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

[BUG] Panic during receiving events occurs #2511

Closed
racoon-devel opened this issue Jun 21, 2022 · 10 comments
Closed

[BUG] Panic during receiving events occurs #2511

racoon-devel opened this issue Jun 21, 2022 · 10 comments

Comments

@racoon-devel
Copy link

Describe the bug

  1. What are you trying to do?
    I'm trying to use pubsub pattern with default broker. v4.7.0

  2. What did you expect to happen?
    Successful publishing and receiving events

  3. What happens instead?

2022-06-21 14:45:59 file=server/rpc_router.go:513 level=error goroutine 84 [running]: runtime/debug.Stack() /usr/lib/go/src/runtime/debug/stack.go:24 +0x65 go-micro.dev/v4/server.(*router).ProcessMessage.func1() /home/racoon/go/pkg/mod/go-micro.dev/v4@v4.7.0/server/rpc_router.go:513 +0xc5 panic({0xf79dc0, 0x11f8aa0}) /usr/lib/go/src/runtime/panic.go:844 +0x258 reflect.Value.Addr({0x10544a0?, 0xc000290ff0?, 0xc0002f6348?}) /usr/lib/go/src/reflect/value.go:273 +0x65 go-micro.dev/v4/server.(*router).ProcessMessage(0xc0001c0ab0, {0x12007a0, 0xc000290fc0}, {0x1202570?, 0xc000632480}) /home/racoon/go/pkg/mod/go-micro.dev/v4@v4.7.0/server/rpc_router.go:560 +0x553 go-micro.dev/v4/server.(*rpcServer).HandleEvent(0xc00017c780, {0x1200ce0?, 0xc000290f60?}) /home/racoon/go/pkg/mod/go-micro.dev/v4@v4.7.0/server/rpc_server.go:129 +0x47a go-micro.dev/v4/broker.(*httpBroker).ServeHTTP(0xc0001fc0f0, {0x11ffd58, 0xc00029e540}, 0xc000220400) /home/racoon/go/pkg/mod/go-micro.dev/v4@v4.7.0/broker/http.go:345 +0xab5 net/http.(*ServeMux).ServeHTTP(0xc00001c147?, {0x11ffd58, 0xc00029e540}, 0xc000220400) /usr/lib/go/src/net/http/server.go:2462 +0x149 net/http.serverHandler.ServeHTTP({0x11fdbf8?}, {0x11ffd58, 0xc00029e540}, 0xc000220400) /usr/lib/go/src/net/http/server.go:2916 +0x43b net/http.(*conn).serve(0xc0005300a0, {0x12007a0, 0xc000290120}) /usr/lib/go/src/net/http/server.go:1966 +0x5d7 created by net/http.(*Server).Serve /usr/lib/go/src/net/http/server.go:3071 +0x4db

How to reproduce the bug:

just run simple example with the newest go-micro version

Environment:
go version go1.18.3 linux/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/racoon/.cache/go-build"
GOENV="/home/racoon/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOMODCACHE="/home/racoon/go/pkg/mod"
GOOS="linux"
GOPATH="/home/racoon/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/racoon/develop/racoon-devel/examples/go.mod"
GOWORK=""
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-build2203251113=/tmp/go-build -gno-record-gcc-switches"
@Davincible
Copy link
Contributor

go-micro/examples#3

@racoon-devel
Copy link
Author

go-micro/examples#3

Using values instead of pointers is not a solution. It works for example, but not for me. I complicated example for understanding problem.

This example worked fine on v2.6.0, but now it fails:
rpc_router.go:560
if err = cc.ReadBody(req.Addr().Interface()); err != nil { return err }
I have json.UnmarshalTypeError here...

@Davincible
Copy link
Contributor

image

Your code works fine for me

@racoon-devel
Copy link
Author

Hm.. Surprise.. I need time to handle it...

@racoon-devel
Copy link
Author

Stop. It's not work. There no messages about events on server! log is empty. In my case too, but i use debugger for determine where errorr occurs

@racoon-devel
Copy link
Author

publishing is success, but receiving does not work

@Davincible
Copy link
Contributor

Ahh I see. I'll have a look

@Davincible
Copy link
Contributor

Jeezz that was a rabbit hole. Turns out the issue is with the json to proto reflection in github.com/golang/protobuf/jsonpb. It fails to unmarshal nested proto messages. If you try to send a proto message without another nested proto message it works fine.

To get the example to work, you would need to get the following to work, as this is basically what happens in the go-micro event handling:

func TestNotification(t *testing.T) {
	ev := &pb.Notification{
		Event: &pb.Event{
			Time: timestamppb.Now(),
			Text: fmt.Sprintf("Messaging you all day on %s", "mytopic"),
		},
		Kind: pb.Notification_DownloadComplete,
	}

	b, _ := json.Marshal(ev)

	t.Log(string(b))

	var out *pb.Notification
	if err := jsonpb.Unmarshal(bytes.NewReader(b), out); err != nil {
		t.Fatal(err)
	}
	t.Logf("Output: %+v\n", out)
}

The high-level go-micro pub/sub methods as used in the example try to be accommodating and allow you to send and receive any type, it does this through reflection, but reflection can be bit wonky at times. The golang/protobuf package is now superseded by the google.golang.org/protobuf package, which doesn't even include the jsonpb package anymore.

If you want to send nested protobuffer events, you will have to marshal/unmarshal them yourself, and pub/sub them as proto/bytes json/string.

Personally, I write my own prototypes using an envelope with a custom decoder, and pub/sub them using the events interface with NATS as backend.

@racoon-devel
Copy link
Author

Ohhh.. I guessed that warning github.com/golang/protobuf is deprected can lead to problems...
Thank you so much, I'll rework my event handling according to this issue..

@jochumdev
Copy link
Contributor

Please note that you need a later version of protoc as well, i use the following Dockerfile for a start:

FROM golang:1.19

# Install packages
RUN apt-get update && \
    apt-get --no-install-recommends --no-install-suggests --yes --quiet install \
        git-core ca-certificates make wget unzip && \
    cd /tmp && wget https://github.com/protocolbuffers/protobuf/releases/download/v21.5/protoc-21.5-linux-x86_64.zip && \
    unzip protoc-21.5-linux-x86_64.zip -d /usr/local/ && chmod +x /usr/local/bin/protoc

# Create appuser (/etc/passwd entry for the runner container)
RUN useradd appuser

# Install protoc-gen-go + protoc-gen-micro
RUN cd /tmp; go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28; go install github.com/go-micro/generator/cmd/protoc-gen-micro@v1.0.0

# Create the Volumes
RUN mkdir /microlobby && chown -R root: /microlobby && cd /microlobby

# Run as user from here
WORKDIR /microlobby

ENV GOPATH="/go"

VOLUME [ "/go", "/microlobby" ]

COPY ./scripts /scripts

@asim asim closed this as completed Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants