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

fix: Fix file descriptor leaks in WriteApi #95

Merged
merged 4 commits into from
Sep 29, 2021
Merged

fix: Fix file descriptor leaks in WriteApi #95

merged 4 commits into from
Sep 29, 2021

Conversation

ecsv
Copy link
Contributor

@ecsv ecsv commented Sep 27, 2021

Proposed Changes

disable creation of WriteApi worker on close

When a worker is created for a flush of the worker on close, it will just create a new object which makes it harder for for the garbage collector to correctly free the unused objects because the Worker itself has a reference to the WriteApi object it called. This is especially frustrating for WriteType::SYNCHRONOUS which doesn't need workers at all.


ensure worker are destroyed after WriteApi::close

The worker will be flushed when something calls close on the WriteApi. But the worker will still continue to hold an reference to the WriteApi. This prevents an easy cleanup of the WriteApi by the (non-cyclic) garbage collector.


clear Client::autoCloseable on close

The autoCloseable list of a client is only growing but is never cleared. This causes problems with the reference based garbage collection. But there is nothing more to process when all writers were closed.

This problem can often be seen on a system that each call of client->createWriteApi (on the same "global" client) followed by a ->write() will leak one or more file descriptor(s).


Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • make test completes successfully
  • Commit messages are in semantic format
  • Sign CLA (if not already signed)

@ecsv ecsv changed the title writerapi: Fix file descriptor leaks in WriteApi fix: Fix file descriptor leaks in WriteApi Sep 27, 2021
When a worker is created for a flush of the worker on close, it will just
create a new object which makes it harder for for the garbage collector to
correctly free the unused objects because the Worker itself has a reference
to the WriteApi object it called. This is especially frustrating for
WriteType::SYNCHRONOUS which doesn't need workers at all.
The worker will be flushed when something calls close on the WriteApi. But
the worker will still continue to hold an reference to the WriteApi. This
prevents an easy cleanup of the WriteApi by the (non-cyclic) garbage
collector.
The autoCloseable list of a client is only growing but is never cleared.
This causes problems with the reference based garbage collection. But there
is nothing more to process when all writers were closed.

This problem can often be seen on a system that each call of
client->createWriteApi (on the same "global" client) followed by a
->write() will leak one or more file descriptor(s).
Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

@ecsv thanks for your PR 👍

Can you please update CHANGELOG.md? After that we can merge this PR into master.

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2021

Codecov Report

Merging #95 (d3bc55b) into master (3f18155) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #95      +/-   ##
============================================
+ Coverage     81.60%   81.66%   +0.06%     
- Complexity      378      379       +1     
============================================
  Files            23       23              
  Lines           897      900       +3     
============================================
+ Hits            732      735       +3     
  Misses          165      165              
Impacted Files Coverage Δ
src/InfluxDB2/Client.php 93.75% <100.00%> (+0.20%) ⬆️
src/InfluxDB2/WriteApi.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f18155...d3bc55b. Read the comment docs.

Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

Thanks again for your PR 👍

@bednar bednar merged commit 8f52ccc into influxdata:master Sep 29, 2021
@bednar bednar added this to the 2.3.0 milestone Sep 29, 2021
@ecsv ecsv deleted the writerapi_leak branch September 29, 2021 06:16
peynman pushed a commit to peynman/influxdb-client-php that referenced this pull request Mar 7, 2023
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