-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Comments
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: |
Hm.. Surprise.. I need time to handle it... |
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 |
publishing is success, but receiving does not work |
Ahh I see. I'll have a look |
Jeezz that was a rabbit hole. Turns out the issue is with the json to proto reflection in 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 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. |
Ohhh.. I guessed that warning |
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 |
Describe the bug
What are you trying to do?
I'm trying to use pubsub pattern with default broker. v4.7.0
What did you expect to happen?
Successful publishing and receiving events
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
The text was updated successfully, but these errors were encountered: