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

Fixes a bug where args were being overridden by previous requests when using requestOptionsTransport #450

Merged
merged 1 commit into from
Jan 12, 2018

Conversation

bertrandom
Copy link
Contributor

Summary

There's a bug when using the requestOptionsTransport where the options object starts storing arguments from previous requests. This makes a clone of the object so that even if it's mutated, a new one is used for each request.

Requirements (place an x in each [ ])

…clone so that requests don't mutate future requests
@codecov
Copy link

codecov bot commented Jan 11, 2018

Codecov Report

Merging #450 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #450      +/-   ##
==========================================
+ Coverage    89.1%   89.12%   +0.01%     
==========================================
  Files          44       44              
  Lines        1258     1260       +2     
  Branches      190      190              
==========================================
+ Hits         1121     1123       +2     
  Misses        137      137
Impacted Files Coverage Δ
lib/clients/transports/request.js 87.5% <100%> (+0.65%) ⬆️

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 081d79c...9910f64. Read the comment docs.

@@ -64,7 +65,8 @@ var proxiedRequestTransport = function proxiedRequestTransport(proxyURL) {

var requestOptionsTransport = function requestOptionsTransport(options) {
return function _requestOptionsTransport(args, cb) {
var requestArgs = defaults(options, getRequestTransportArgs(args));
var instanceOptions = cloneDeep(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

could this line be outside of the inner _requestOptionsTransport function? or in other words, what's the point in cloning the options each time a request is fired, as opposed to just cloning it once per transport "constructed"?

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 think the problem is that the way defaults works is by putting instanceOptions as the base of requestArgs and then layering the args on top of it. This means that after the args are layered on top, instanceOptions has now been overridden with the args specified by the caller.

This is problematic for the next request because then instanceOptions now also includes the args from the previous request. By ensuring that the original options object doesn't mutate and cloning it for each request, we avoid this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah! i was assuming defaults() is a pure function. silly lodash developers. 👍

@aoberoi aoberoi merged commit c3c015a into slackapi:master Jan 12, 2018
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.

None yet

2 participants