Skip to content

Conversation

@ajay-vel
Copy link
Contributor

@ajay-vel ajay-vel commented Jun 23, 2022

Desired Outcome

The desired outcome of this PR is to resolve the memory leak in the postgres container causing it to OOM.

Implemented Changes

This PR:

Makes use of ShardedThreadedConnectionPool in Sequel so that active connections can be closed.
Closing active connections from conjur ensures that memory consumption in postgres stays low and a new connection for conjur is established every-time on policy load instead of using the existing connection.

- Connected Issue/Story

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: insert issue ID
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@ajay-vel ajay-vel requested a review from a team as a code owner June 23, 2022 21:53
@ajay-vel ajay-vel force-pushed the fix-postgres-memory-usage branch from da207fa to 29c5d25 Compare June 27, 2022 15:04
Copy link
Contributor

@micahlee micahlee left a comment

Choose a reason for hiding this comment

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

This a couple of further follow ups. Also, I'm not entirely sure if it was accidental or intentional, but we should spell out 'policy' in the commit message (plcy -> policy).

If you're trying to use a shorter message, I would suggest changing the headline and adding a body like:

Disconnect the database connection after policy loads

... Add more detail about why (Postgres's catcache) and how (with the shardedconnection pool) in the commit message body...

@ajay-vel ajay-vel force-pushed the fix-postgres-memory-usage branch from 9aeb86e to 55f247f Compare June 28, 2022 19:59
micahlee
micahlee previously approved these changes Jun 28, 2022
Copy link
Contributor

@micahlee micahlee left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding the extra comments, @ajay-vel !

PostgreSQL has many types of caches, one of which is the "catalog cache".When a connection is established to the database, this cache is initialized alongside it, and persists for the duration of the connection. This cache contains references to Database Objects, such as indexes, etc. (not data records themselves).This cache is not cleaned up by the system automatically. However, if the connection is disconnected, the cache is dumped. Further reading: Postgres community email thread: https://www.postgresql.org/message-id/flat/20161219.201505.11562604.horiguchi.kyotaro@lab.ntt.co.jp. The default connection pool does not support closing connections.We must be able to close connections on demand, to clear the connection cache after policy loads. The ShardedThreadedConnectionPool does support closing connections on-demand [docs](https://www.rubydoc.info/github/jeremyevans/sequel/Sequel/ShardedThreadedConnectionPool)
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit af95002 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Style 1

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 89.8%.

View more on Code Climate.

@ajay-vel ajay-vel merged commit 8938d34 into master Jun 29, 2022
@ajay-vel ajay-vel deleted the fix-postgres-memory-usage branch June 29, 2022 15:27
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.

2 participants