apache / rocketmq-client-go

Apache RocketMQ go client
https://rocketmq.apache.org/
Apache License 2.0
1.3k stars 421 forks source link

`RequestResponseFutureMap` is not loaded lazily and creates a goroutine just by importing this package #1068

Open ItalyPaleAle opened 1 year ago

ItalyPaleAle commented 1 year ago

BUG REPORT

This is an issue we've discovered in Dapr because we offer support for RocketMQ.

  1. Please describe the issue you observed:

    • What did you do (The steps to reproduce)? Import the rocketmq-client-go library, even if no client is initialized

    • What did you expect to see? Nothing should happen - the library should not initialize objects just because it's imported. All caches should be loaded lazily.

    • What did you see instead? This line causes RequestResponseFutureMap to be initialized as a global variable, which allocates a requestResponseFutureCache and spawns a goroutine

  2. Please tell us about your environment:

    • What is your OS? Linux/amd64

    • What is your client version? 2.1.2

    • What is your RocketMQ version? N/A

  3. Other information (e.g. detailed explanation, logs, related issues, suggestions on how to fix, etc):

francisoliverlee commented 1 year ago

what's your ideas ?

ItalyPaleAle commented 1 year ago

@francisoliverlee I am not familiar with this library enough to suggest how it should be changed, but the general pattern is to initialize these things lazily.

That is: the object is only initialized (and the goroutine started) when it's first needed.