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

Client.close(true) does not release underlying event loop #603

Open
matveym opened this issue Jan 26, 2024 · 2 comments
Open

Client.close(true) does not release underlying event loop #603

matveym opened this issue Jan 26, 2024 · 2 comments

Comments

@matveym
Copy link

matveym commented Jan 26, 2024

While running tests from different modules via Jest I encountered an issue that Client.close(true) does not close the underlying event loop. As a result, subsequent Client.connect() calls fail with "Unable to register default event loop: Failed to add external loop. Capacity is 1 [-1]".
As far as I've investigated, the root cause is a bug inside Aerospike C client: https://github.com/aerospike/aerospike-client-c/blob/master/src/main/aerospike/as_event.c#L338. as_event_destroy_loops() is called inside if (as_event_threads_created && status){...} block, but Client.connect() calls as_event_set_external_loop_capacity(1), which in turn sets as_event_threads_created = false. As a result, as_event_destroy_loops() never gets called.
See more details here: https://discuss.aerospike.com/t/jest-sequentially-run-tests-are-failed/10307/8

@DomPeliniAerospike
Copy link
Collaborator

Hi @matveym,

I replied to the post you mentioned, and I don't think this constitutes a bug. The eventLoop is designed to only be released at the end of the process execution, and the same eventLoop should be referenced rather than creating and destroying multiple eventLoops. Using the workaround provided in the discussion post above, we should be able to maintain this behavior.

@matveym
Copy link
Author

matveym commented Jan 30, 2024

Hi @DomPeliniAerospike. Thank you for such a detailed and clear answer. I learned a lot from it and will try to rewrite our tests.
I still have one question left - what's the use of the releaseEventLoop parameter in Client.close() method? As far as I understood from code (please correct me if I'm wrong):

  1. Client.close() will call EventLoop.releaseEventLoop() for the last connection (OK)
  2. EventLoop.releaseEventLoop() will call native C function release_as_event_loop() from aerospike.cc (OK)
  3. release_event_loop() will call as_event_close_loops() function from Aerspike C client library (OK)
  4. as_event_close_loops() will do nothing - will not call as_event_destroy_loops() as as_event_threads_created = false (set by call to as_event_set_external_loop_capacity() from aerospike.cc:register_as_event_loop()) (not OK)

This means that Client.close(true) will never release event loop. Does it have some other use? What's the purpose of releaseEventLoop parameter?

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

No branches or pull requests

2 participants