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

Master code reset consumer offset cause program exit #759

Closed
lifepuzzlefun opened this issue Dec 21, 2021 · 8 comments · Fixed by #765
Closed

Master code reset consumer offset cause program exit #759

lifepuzzlefun opened this issue Dec 21, 2021 · 8 comments · Fixed by #765
Labels
bug Something isn't working

Comments

@lifepuzzlefun
Copy link
Contributor

lifepuzzlefun commented Dec 21, 2021

  1. Please describe the issue you observed:

    1. start local RocketMQ cluster

    2. use example/consumer/simple/main.go start a consumer.

    3. use ./mqadmin resetOffset tool to reset offset.

    4. consumer process exit with.

      INFO[0005] receive reset consumer offset request... broker="127.0.0.1:30931" consumerGroup=groupB timestamp=631123200000 topic=topicB
      panic: runtime error: index out of range [1] with length 1
      goroutine 113 [running]:
      github.com/apache/rocketmq-client-go/v2/internal.(*ResetOffsetBody).Decode(0xc000461d20, {0xc00040c100, 0xfd, 0xfd})
      /Users/bytedance/github/rocketmq-client-go/internal/model.go:309 +0xa45
      github.com/apache/rocketmq-client-go/v2/internal.GetOrNewRocketMQClient.func5(0xc000416a80, {0x14ed5c8, 0xc0003260c0})
      /Users/bytedance/github/rocketmq-client-go/internal/client.go:303 +0x3f8
      github.com/apache/rocketmq-client-go/v2/internal/remote.(*remotingClient).processCMD.func2()
      /Users/bytedance/github/rocketmq-client-go/internal/remote/remote_client.go:207 +0x94
      github.com/apache/rocketmq-client-go/v2/primitive.WithRecover(0xc000421ef0)
      /Users/bytedance/github/rocketmq-client-go/primitive/base.go:100 +0x47
      created by github.com/apache/rocketmq-client-go/v2/internal/remote.(*remotingClient).processCMD
      /Users/bytedance/github/rocketmq-client-go/internal/remote/remote_client.go:206 +0x378
      Exiting.

    
    
  2. Please tell us about your environment:
    mac local
    master client-go code.
    rocketmq broker with fastjson-1.2.76.jar

  3. Other information (e.g. detailed explanation, logs, related issues, suggestions on how to fix, etc):
    the test code in decode ResetOffsetBody json format is different from mine

mine from rocketmq broker response rpc

{"offsetTable":{{"brokerName":"RaftNode00","queueId":0,"topic":"topicB"}:0,{"brokerName":"RaftNode00","queueId":1,"topic":"topicB"}:0,{"brokerName":"RaftNode00","queueId":2,"topic":"topicB"}:0,{"brokerName":"RaftNode00","queueId":3,"topic":"topicB"}:0}}

any different from fastjson config ?

@lifepuzzlefun
Copy link
Contributor Author

@maixiaohai hello,can you check this problem. i think the json is not the same cause the parse problem. what is your fastjson version

@lifepuzzlefun
Copy link
Contributor Author

more context: see

func TestRestOffsetBody_MarshalJSON(t *testing.T) {
Convey("test ResetOffset Body Decode", t, func() {
body := "{\"offsetTable\":[[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":5},23354233],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":4},23354245],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":7},23354203],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":6},23354312],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":1},23373517],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":0},23373350],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":3},23373424],[{\"topic\":\"zx_tst\",\"brokerName\":\"tjwqtst-common-rocketmq-raft0\",\"queueId\":2},23373382]]}"
resetOffsetBody := new(ResetOffsetBody)
resetOffsetBody.Decode([]byte(body))
offsetTable := resetOffsetBody.OffsetTable
So(offsetTable, ShouldNotBeNil)
So(len(offsetTable), ShouldEqual, 8)
messageQueue := primitive.MessageQueue{
Topic: "zx_tst",
BrokerName: "tjwqtst-common-rocketmq-raft0",
QueueId: 5,
}
So(offsetTable[messageQueue], ShouldEqual, 23354233)
})
}

@wenfengwang
Copy link
Member

@WJL3333 Thanks for your report, Could you have any idea for fixing this?

@lifepuzzlefun
Copy link
Contributor Author

@wenfengwang i think the json decode method cause this problem. the current json here is different from my rocketmq cluster, fastjson-1.2.76.jar i wonder if there is some special config for json serialization? if we can find why json is different, may be use different json lib in rocketmq or different fastjson version? the fix is apperent.

@maixiaohai
Copy link
Contributor

@maixiaohai hello,can you check this problem. i think the json is not the same cause the parse problem. what is your fastjson version

We use Gson internal, can you help fix this?

@maixiaohai maixiaohai added the bug Something isn't working label Dec 25, 2021
@lifepuzzlefun
Copy link
Contributor Author

yes, but should we just follow the fastjson schema, and change the origin gson format? @maixiaohai @wenfengwang

@maixiaohai
Copy link
Contributor

yes, but should we just follow the fastjson schema, and change the origin gson format? @maixiaohai @wenfengwang

Yeah, fastjson format is original currently. RMQ server use fastjson to encode and decode as default.
And Fastjson has security problem and produce some non-standard json schema. Only change the client schema can not solve this problem.
This is a related issue to describe the background apache/rocketmq#2462.

@lifepuzzlefun
Copy link
Contributor Author

yes, i agree with you. the non-standard json schema is very annoying when port some admin interface from java to go.
and for this case. i will try to parse response json first. if we found this is non-standard json schema. the code will try to parse response as fastjson format.

wenfengwang pushed a commit that referenced this issue Jan 3, 2022
ISSUE #759] Change ResetOffsetBody response parse method to support fastjson schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants