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

Ensure sessions are correctly deleted from ETS by passing the pid along #558

Merged
merged 5 commits into from
Aug 1, 2020

Conversation

bobwaycott
Copy link
Contributor

ETS records weren't being correctly removed from SessionStore, leaving stale sessions around in SessionStore.list_sessions_for. By returning the pid from the :ets.select, we can ensure a correct match & delete of the session.

Could be useful to add a defdelegate active_sessions in the main Wallaby interface that calls SessionStore.list_sessions_for, but didn't want to make that assumption in this PR.

Fixes the issue pointed out in #550

@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2020

Codecov Report

Merging #558 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #558   +/-   ##
=======================================
  Coverage   92.73%   92.73%           
=======================================
  Files          26       26           
  Lines         853      853           
=======================================
  Hits          791      791           
  Misses         62       62           
Flag Coverage Δ
#IntegrationTest 87.69% <100.00%> (ø)
#UnitTest 43.96% <100.00%> (+4.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/wallaby/session_store.ex 95.45% <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 834bdb7...23e7e77. Read the comment docs.

@bobwaycott bobwaycott changed the title Ensure sessions are correctly deleted from ETS by passing the pid along Ensure sessions are correctly deleted from ETS by passing the pid along Jul 31, 2020
@mhanberg
Copy link
Member

Thanks for the PR! Do you mind adding some tests?

@bobwaycott
Copy link
Contributor Author

There are currently no tests for SessionStore in the project. What are your thoughts on how SessionStore should be tested?

@mhanberg
Copy link
Member

It think it's fine to create a new unit test module for the session store, and test that it can store and delete multiple sessions for the same test pid, and remove them both when that test pid goes down.


case result do
[{ref, _}] ->
[{ref, pid, _session}] ->
Copy link
Member

Choose a reason for hiding this comment

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

should this be [{ref, _session, pid}]?

Copy link
Contributor Author

@bobwaycott bobwaycott Jul 31, 2020

Choose a reason for hiding this comment

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

No, but I can switch the return value order to match the way the data is stored in ETS. This match is based on the way the result is returned from, not stored in ETS (you can see the :ets.delete call matches the storage order.

EDIT: The ordering is a result of this call:

result =
      :ets.select(:session_store, [
        {{{:"$1", :"$2", :"$3"}, :"$4"}, [{:==, :"$2", session.id}], [{{:"$1", :"$3", :"$4"}}]}
        ])

I can swap the [{{:"$1", :"$3", :"$4"}}]} and make it [{{:"$1", :"$4", :"$3"}}]} to keep the order matched.

However, do we really even need to return the session itself? We could probably get away with just returning the session.id value (or not at all). We already have the session passed in, and only need the session.id to successfully delete.

EDIT 2: I think it'd be worth making that return value just the ref, pid pair, because we can use that + the passed in session.id to cleanly and correctly delete.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see now that I misread it.

@bobwaycott
Copy link
Contributor Author

bobwaycott commented Jul 31, 2020

@mhanberg added a couple straightforward tests to verify the ETS table adds & correctly removes sessions. I also streamlined the queries just a tad for unused params

Copy link
Member

@mhanberg mhanberg left a comment

Choose a reason for hiding this comment

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

thanks!

@mhanberg mhanberg merged commit b25e693 into elixir-wallaby:master Aug 1, 2020
@bobwaycott
Copy link
Contributor Author

Happy to help!

@bobwaycott
Copy link
Contributor Author

@mhanberg sorry to comment again on a closed PR, but wanted to check in on what the release cycle is like for wallaby being updated in Hex? Would love to have this fix available, and curious if I should install from github, or if a new release will be made with this fix?

@mhanberg
Copy link
Member

mhanberg commented Aug 3, 2020

I'm currently adding some more tests. I'll release a patch release once I'm done with that. You can install from github master until then if you'd like.

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