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

Make sure local cache cleared even it's throwing: #28373

Merged
merged 1 commit into from Mar 10, 2017

Conversation

Projects
None yet
5 participants
@godfat
Contributor

godfat commented Mar 10, 2017

We (GitLab) hit into an issue that somewhere in the middleware
chain was throwing :warden, which was caught in the wrapping
middleware, but LocalCache::Middleware was not aware of it.
It should look like:

result = catch(:warden) do
  @app.call(env)
end

Source: https://github.com/hassox/warden/blob/090ed153dbd2f5bf4a1ca672b3018877e21223a4/lib/warden/manager.rb#L35-L37

Using ensure could make sure that we would always do the cleanup,
and better yet, avoid rescue Exception which we all should know
that could cause some issues which could be very hard to debug.

Please check the discussion thread for more context:
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1402#note_25128108

/cc @stanhu @rymai

Make sure local cache cleared even it's throwing:
We (GitLab) hit into an issue that somewhere in the middleware
chain was throwing `:warden`, which was caught in the wrapping
middleware, but `LocalCache::Middleware` was not aware of it.
It should look like:

``` ruby
result = catch(:warden) do
  @app.call(env)
end
```

Source: https://github.com/hassox/warden/blob/090ed153dbd2f5bf4a1ca672b3018877e21223a4/lib/warden/manager.rb#L35-L37

Using `ensure` could make sure that we would always do the cleanup,
and better yet, avoid `rescue Exception` which we all should know
that could cause some issues which could be very hard to debug.

Please check the discussion thread for more context:
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1402#note_25128108
@rails-bot

This comment has been minimized.

rails-bot commented Mar 10, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@rafaelfranca rafaelfranca merged commit c56c4e4 into rails:master Mar 10, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate no new or fixed issues
Details

rafaelfranca added a commit that referenced this pull request Mar 10, 2017

Merge pull request #28373 from godfat/fix-cache-middleware-with-throw
Make sure local cache cleared even it's throwing:
@rafaelfranca

This comment has been minimized.

Member

rafaelfranca commented Mar 10, 2017

Backported in c644af7

@godfat

This comment has been minimized.

Contributor

godfat commented Mar 11, 2017

@godfat

This comment has been minimized.

Contributor

godfat commented Mar 11, 2017

godfat added a commit to godfat/warden that referenced this pull request Nov 16, 2017

Make it able to throw in Warden::Manager.on_request
In `Warden::Test::Helpers#login_as`, it's using
`Warden.on_next_request`, which is using
`Warden::Manager.on_request`, and it would call
`proxy.set_user` which would possibly throw.

This means before this patch, `Proxy.new` could
throw in the tests. We're also expecting `env['warden']`
to be set in `Warden::Manager`, therefore we need to
decouple initializing the object and calling the `on_request`
callbacks, and move `env['warden'].on_request` inside the
`catch` block to handle the logging in process properly
in the tests.

I am not sure if people are relying on this behaviour
other than tests, but I assume it's not bad to be able to
`throw` in `Warden::Manager.on_request` as a way to
stop the chain early.

Without this patch, in the tests, `:warden` would be thrown
whenever it failed to login. People might be depending on
this behaviour, but throwing symbols like this could break
people's cleanup code.

Here's an example: rails/rails#28373

Rails was using `rescue Exception` before to cleanup stuffs,
but it would not be rescuing any symbols. There were other
codes doing things like this, causing some weird transient
test failures like this for GitLab:
https://gitlab.com/gitlab-org/gitlab-ce/issues/40093

In short, we shouldn't let any `throw` bubble up. The other
way to fix this would be not using `Warden::Manager.on_request`
to login, but that might need more changes and could break
even more codes. Also, I think it's not bad to be able to
`throw :warden` in `Warden::Manager.on_request`.

godfat added a commit to godfat/warden that referenced this pull request Nov 16, 2017

Make it able to throw in Warden::Manager.on_request
In `Warden::Test::Helpers#login_as`, it's using
`Warden.on_next_request`, which is using
`Warden::Manager.on_request`, and it would call
`proxy.set_user` which would possibly throw.

This means before this patch, `Proxy.new` could
throw in the tests. We're also expecting `env['warden']`
to be set in `Warden::Manager`, therefore we need to
decouple initializing the object and calling the `on_request`
callbacks, and move `env['warden'].on_request` inside the
`catch` block to handle the logging in process properly
in the tests.

I am not sure if people are relying on this behaviour
other than tests, but I assume it's not bad to be able to
`throw` in `Warden::Manager.on_request` as a way to
stop the chain early.

Without this patch, in the tests, `:warden` would be thrown
whenever it failed to login. People might be depending on
this behaviour, but throwing symbols like this could break
people's cleanup code.

Here's an example: rails/rails#28373

Rails was using `rescue Exception` before to cleanup stuffs,
but it would not be rescuing any symbols. There were other
codes doing things like this, causing some weird transient
test failures like this for GitLab:
https://gitlab.com/gitlab-org/gitlab-ce/issues/40093

In short, we shouldn't let any `throw` bubble up. The other
way to fix this would be not using `Warden::Manager.on_request`
to login, but that might need more changes and could break
even more codes. Also, I think it's not bad to be able to
`throw :warden` in `Warden::Manager.on_request`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment