Skip to content

Optimize session cache flushing#8687

Closed
tmshort wants to merge 2 commits intoopenssl:masterfrom
akamai:master-flush
Closed

Optimize session cache flushing#8687
tmshort wants to merge 2 commits intoopenssl:masterfrom
akamai:master-flush

Conversation

@tmshort
Copy link
Contributor

@tmshort tmshort commented Apr 5, 2019

Sort SSL_SESSION structures by timeout in the linked list.
Iterate over the linked list for timeout, stopping when no more
session can be flushed.
Do SSL_SESSION_free() outside of SSL_CTX lock
Update timeout upon use

Checklist
  • tests are added or updated

@tmshort
Copy link
Contributor Author

tmshort commented Apr 5, 2019

This does update the timeout upon use; which is a behavior change. This could instead be an option on the SSL_CTX to which it has been added (so, new API)

@FdaSilvaYY
Copy link
Contributor

typo in commit heading message and PR Title ;)

@tmshort tmshort changed the title Optimize sesion cache flushing Optimize session cache flushing Apr 8, 2019
@tmshort
Copy link
Contributor Author

tmshort commented Apr 8, 2019

Added unit tests

@tmshort
Copy link
Contributor Author

tmshort commented Apr 8, 2019

Rebase, fix comment, fix CI (I hope)

@tmshort
Copy link
Contributor Author

tmshort commented Apr 10, 2019

Travis failure seems to be a build timeout?

@tmshort
Copy link
Contributor Author

tmshort commented Apr 10, 2019

Added option to update the time upon add.

ssl/ssl_sess.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is inviting controversy to propose, but we may want to assert (in some form) that next != NULL after this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above as to what the proposed assert should check.

@tmshort
Copy link
Contributor Author

tmshort commented Oct 3, 2019

Thanks @paulidale, we actually backed this out of our repo because it caused a problem... or exposed a problem... we're not exactly sure, but we had some weird behavior with this.

@paulidale
Copy link
Contributor

Should this be closed then?

@tmshort
Copy link
Contributor Author

tmshort commented Oct 3, 2019

No, we need to test it more. If you see anything obvious; great. But I think it exposed a problem we had, and we actually need to clean up the other code (which is PR #3761).

@tmshort
Copy link
Contributor Author

tmshort commented Jul 15, 2020

This exposed a problem in some of our other changes @paulidale, so it's actually good.

@tmshort tmshort force-pushed the master-flush branch 2 times, most recently from ca21130 to 394a332 Compare August 31, 2020 22:01
@tmshort tmshort requested review from kaduk and paulidale August 31, 2020 22:02
@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 92 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 123 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 154 days ago

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 185 days ago

@tmshort
Copy link
Contributor Author

tmshort commented May 20, 2021

ping @mattcaswell ?

@FdaSilvaYY
Copy link
Contributor

Ping @openssl : this PR is failing in the limbo.

ssl/ssl_sess.c Outdated
Copy link
Member

Choose a reason for hiding this comment

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

This reads s->time with no lock, and then subsequently writes to it under a write lock. Shouldn't there be a read lock here?

Copy link
Contributor Author

@tmshort tmshort Jun 1, 2021

Choose a reason for hiding this comment

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

Not necessarily. It's checking to see if it's different; the actual value doesn't matter. This is an optimization to see if it should be updated. Previously it would just slam the time into the session without any locking at all. Any manipulation is done under lock. But note that the lock only happens if the session is in a SSL_CTX cache; the SSL_SESSION structure does not have a lock.

Copy link
Member

Choose a reason for hiding this comment

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

But if s->owner is non-NULL then we know that the session has already been placed in the cache and therefore taking a read lock might be appropriate. It definitely seems odd to control writes with a write lock, but not reads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would agree 100% if the value read were used for something meaningful. In this case, it's really not. It's read to see if there needs to be a change. If so, do the update; the prior value doesn't matter.
Because of that, locking for read here is pointless; if we're always going to lock, then we might as well always update, and remove the (albeit minor) optimization. I can make that change (unless my argument is convincing 😄 ).

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to see it modified as you suggest.

ssl/ssl_sess.c Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Reads s->timeout not under lock, and then subsequently writes to it under lock. This seems wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as before.

@tmshort
Copy link
Contributor Author

tmshort commented Jun 1, 2021

@mattcaswell lots (most?) of the code was originally written w/o read locks; this doesn't really change that.

Sort SSL_SESSION structures by timeout in the linked list.
Iterate over the linked list for timeout, stopping when no more
session can be flushed.
Do SSL_SESSION_free() outside of SSL_CTX lock
Update timeout upon use
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Jun 1, 2021
@mattcaswell
Copy link
Member

@mattcaswell lots (most?) of the code was originally written w/o read locks; this doesn't really change that.

I'm satisfied with most of the answers - although I've left 2 comments unresolved which I'm still not convinced about.

@github-actions github-actions bot removed the severity: fips change The pull request changes FIPS provider sources label Jun 4, 2021
@tmshort
Copy link
Contributor Author

tmshort commented Jun 8, 2021

@mattcaswell I think I made the requested changes.

@mattcaswell
Copy link
Member

@paulidale - please can you reconfirm your earlier approval?

@paulidale paulidale added the approval: done This pull request has the required number of approvals label Jun 9, 2021
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jun 10, 2021
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@paulidale
Copy link
Contributor

Merged, thanks for this.

@paulidale paulidale closed this Jun 10, 2021
openssl-machine pushed a commit that referenced this pull request Jun 10, 2021
Sort SSL_SESSION structures by timeout in the linked list.
Iterate over the linked list for timeout, stopping when no more
session can be flushed.
Do SSL_SESSION_free() outside of SSL_CTX lock
Update timeout upon use

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #8687)
@tmshort tmshort deleted the master-flush branch June 11, 2021 21:00
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
Sort SSL_SESSION structures by timeout in the linked list.
Iterate over the linked list for timeout, stopping when no more
session can be flushed.
Do SSL_SESSION_free() outside of SSL_CTX lock
Update timeout upon use

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#8687)
@wbl wbl mentioned this pull request Apr 27, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge approval: review pending This pull request needs review by a committer branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants