Skip to content

Conversation

@brycezhongqing
Copy link
Collaborator

Fix a corner case bug in d2ClientBuilder shutdown logic.

Corner case: when _config._executorService == null

  if (_config._executorService == null)
    {
      LOG.warn("No executor service passed as argument. Pass it for " +
        "enhanced monitoring and to have better control over the executor.");
      _config._executorService =
        Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("D2 PropertyEventExecutor"));
      executorsToShutDown.add(_config._executorService);
    }

Then _executorService will be added to executorsToShutDown. Finally, when d2Client call the shutdown method, the _executorService may be closed twice. Like

  1. first place
  2. second place

@brycezhongqing brycezhongqing force-pushed the zhonchen/fix_d2_client_builder_shutdown branch from e4f9a3b to 3de0c00 Compare April 9, 2025 00:40
@brycezhongqing brycezhongqing changed the title fix d2 client builder shutdown fix d2ClientBuilder shutdown corner case Apr 9, 2025
Copy link
Contributor

@bohhyang bohhyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the first place be removed then? if the executors are shut down in the second place. But I guess it's ok as long as the second place has the isShutdown check guard.

{
if (executor.isShutdown())
{
LOG.warn("Executor is already shut down");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need warning, info level is fine.

@brycezhongqing
Copy link
Collaborator Author

should the first place be removed then? if the executors are shut down in the second place. But I guess it's ok as long as the second place has the isShutdown check guard.

Sadly. No. As executorsToShutDown.add(_config._executorService); will only execute when if (_config._executorService == null)

If _config._executorService != null, the first place should be executed

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

Successfully merging this pull request may close these issues.

3 participants