Closed
Description
Describe the bug
- Node.js version: 12.16.3
- Got: 11.1.0
- OS & version: MacOS (latest)
This issue was discovered while investigating #1221
Here you can see two after response hooks. But in the code you provided there's only one. Another bug here?
I need your input on this too :)
Guess what? I have one single afterResponse
hook.
Now if I inspect normalizedOptions.hooks.afterResponse
in node_modules/got/dist/source/create.js@94
, its length double at each iteration (i.e. 2 at page 2, 4 at page 3, 8 at page 4, etc.)
Funny for I was about to add my share to #1220 .
Actual behavior
the hooks.afterResponse
array is double with each pagination.paginate()
iteration
Expected behavior
the hooks.afterResponse
array should not changed during pagination()
processing
Code to reproduce
...
Checklist
- I have read the documentation.I have tried my code with the latest version of Node.js and Got.
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
PopGoesTheWza commentedon May 6, 2020
@szmarczak Here is an ugly but functional test case.
// Nicer test case in PR #1231
Add test cases for issues #1221 and #1223 (#1231)
PopGoesTheWza commentedon May 7, 2020
Kludgy workaround, add this line first in your
pagination.paginate
custom function:cacheable-lookup@^4.2.3
) causes a memory leak #1220szmarczak commentedon May 10, 2020
That's actually an invalid use case. The options are merged. You return the request options, which already include hooks. But I'm fixing it rn.
PopGoesTheWza commentedon May 10, 2020
Using Got@11.1.3 without the above kludge:
szmarczak commentedon May 10, 2020
Are you sure you're not doing
return {...response.request.options}
?szmarczak commentedon May 10, 2020
The tests are passing...
PopGoesTheWza commentedon May 10, 2020
Odd. Tests do pass indeed.But real use case fails without the kludge (I double checked with and without twice.)
But it seems to takes longer to crash though.
I guess I need to debug deeper and check what is happening.
The effective
hooks
is a merge of the defaults and the current options, right?PopGoesTheWza commentedon May 10, 2020
Hold on. You're right. And re-reading the
pagination.paginate
definition, I see that I intepret it not as intended. Returning theoptions
to the next page... It implies though not specifically that it is only the difference from current options.I am reading it right now?
szmarczak commentedon May 10, 2020
yes.
szmarczak commentedon May 10, 2020
Cuz I have just updated the readme lol, no worries.
4 remaining items