Uploaded image for project: 'Apache RocketMQ'
  1. Apache RocketMQ
  2. ROCKETMQ-107

Access ServiceState is not thread safe when start() or shutdown()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.0.0-incubating
    • Fix Version/s: 4.1.0-incubating
    • Component/s: rocketmq-client
    • Labels:
      None

      Description

      When start() or shutdown(), service's state is not thread safe which may break happen-before.

      For example:

      switch (this.serviceState) {
                  case CREATE_JUST:
                      log.info("the consumer [{}] start beginning. messageModel={}, isUnitMode={}", this.defaultMQPushConsumer.getConsumerGroup(),
                          this.defaultMQPushConsumer.getMessageModel(), this.defaultMQPushConsumer.isUnitMode());
                      this.serviceState = ServiceState.START_FAILED;
                      ..// do some start job here
                      this.serviceState = ServiceState.RUNNING;
                      break;
                  case RUNNING:
                  case START_FAILED:
                  case SHUTDOWN_ALREADY:
                      throw new MQClientException("The PushConsumer service state not OK, maybe started once, "//
                          + this.serviceState//
                          + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
                          null);
                  default:
                      break;
              }
      

      1. If the user is start twice in two thread, the resources may initize twice.
      2. if the user start in threadA and shutdown very quicky in another thread B, shutdown may not reclaim the resources.

      Though the sceniro is very uncommon, but it is indeed a bug here. Fix is actually quite trivial.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Jaskey Jaskey Lam
                Reporter:
                Jaskey Jaskey Lam
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: