hedera-sdk-java icon indicating copy to clipboard operation
hedera-sdk-java copied to clipboard

Client should not shutdown provided executor

Open OlegMazurov opened this issue 1 year ago • 4 comments

Description

#1844 introduced a new API that allowed creating Clients with an external Executor. Multiple Clients can now share the same executor. However, when a Client is closed it shuts down its executor no matter whether it was provided or created by the client itself. That affects multiple clients sharing the same executor, reusing the executor for a client that had to be restarted, and lots of other scenarios where users assume control over their executor.

Steps to reproduce

  • Create two Clients with the same external executor
  • Close one Client
  • Continue using the second Client

Additional context

No response

Hedera network

other

Version

2.39.0

Operating system

Linux

OlegMazurov avatar Oct 11 '24 23:10 OlegMazurov

Hi Oleg, you could use client.closeChannels();, which will not shutdown the executor.

0xivanov avatar Oct 14 '24 06:10 0xivanov

This is counterintuitive from the API point of view and I expect every developer to fall for it. I'll update my client code as suggested. However, the point that SDK should not close user provided executor is still valid.

OlegMazurov avatar Oct 15 '24 15:10 OlegMazurov

@0xivanov would a solution be to track if the executor was user-provided or not, and in the former case, do not close it?

steffenboe avatar Oct 18 '24 13:10 steffenboe

@steffenboe Yes, we could do that. If you feel like doing this, I don't have any problems with that.

0xivanov avatar Oct 21 '24 06:10 0xivanov