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 bugs in Lua implementation of sticky sessions #2484

Merged
merged 1 commit into from
May 17, 2018

Conversation

ElvinEfendi
Copy link
Member

@ElvinEfendi ElvinEfendi commented May 9, 2018

What this PR does / why we need it:
I've detected two bugs with current implementation of sticky sessions in Lua:

  • it does not re-set the cookie after setting it for the first time this should be the case - just make it a session cookie
  • it uses shared lua dictionary which is per replica - so as soon as next request from same cookie goes to another replica it will potentially be proxied to a different upstream

The PR adds regression test and fix the bugs.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 9, 2018
@ElvinEfendi ElvinEfendi changed the title Fix bugs in Lua implementation of sticky sessions [WIP] Fix bugs in Lua implementation of sticky sessions May 9, 2018
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 9, 2018
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 10, 2018
@ElvinEfendi ElvinEfendi mentioned this pull request May 10, 2018

if backend["upstream-hash-by"] then
if is_sticky(backend) or backend["upstream-hash-by"] then
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the only reason this or is there is to not repeat fetching the endpoint (L57 - L60).

You will have some repeated code here - but I would separate the conditions (is_sticky(backend) and backend["upstream-hash-by"]) to keep it easy to read. This way you could also take out the condition on L62.


local ok
ok, err = cookie:set({
key = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["name"] or "route",
Copy link
Contributor

Choose a reason for hiding this comment

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


local endpoint_string = endpoint.address .. ":" .. endpoint.port
local encrypted
if backend["sessionAffinityConfig"]["cookieSessionAffinity"]["hash"] == "sha1" then
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to have a helper method here that generates the digested endpoint string rather than doing it over here.

@ElvinEfendi ElvinEfendi force-pushed the lua-sticky-session-bug branch 3 times, most recently from 1930ac5 to 8588dde Compare May 16, 2018 21:17
@ElvinEfendi ElvinEfendi changed the title [WIP] Fix bugs in Lua implementation of sticky sessions Fix bugs in Lua implementation of sticky sessions May 16, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 16, 2018
@codecov-io
Copy link

codecov-io commented May 16, 2018

Codecov Report

Merging #2484 into master will decrease coverage by 0.09%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #2484     +/-   ##
=========================================
- Coverage   41.66%   41.57%   -0.1%     
=========================================
  Files          74       74             
  Lines        5282     5270     -12     
=========================================
- Hits         2201     2191     -10     
+ Misses       2783     2782      -1     
+ Partials      298      297      -1
Impacted Files Coverage Δ
internal/file/bindata.go 61.34% <ø> (-1.06%) ⬇️

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 94198fc...7ac4e1d. Read the comment docs.

@ElvinEfendi
Copy link
Member Author

CI is failing because if a flaky test that's fixed at #2526. I'll rebase once that gets merged.

@ElvinEfendi
Copy link
Member Author

/assign @aledbf

@aledbf
Copy link
Member

aledbf commented May 17, 2018

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 17, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, ElvinEfendi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 17, 2018
@k8s-ci-robot k8s-ci-robot merged commit ee7a63d into kubernetes:master May 17, 2018
@ElvinEfendi ElvinEfendi deleted the lua-sticky-session-bug branch May 17, 2018 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants