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

Agent executes "end()" callback before setting cookies #314

Closed
vsuhanov opened this issue Jan 24, 2014 · 24 comments
Closed

Agent executes "end()" callback before setting cookies #314

vsuhanov opened this issue Jan 24, 2014 · 24 comments

Comments

@vsuhanov
Copy link

when using agent to keep persistent cookies it executes end callback before agent saves cookies and the next request might not have these cookies set.

here is an example of test that fails when it should not.
https://gist.github.com/vsuhanov/8599800

possible solution:

  1. try to insert event handler, that saves cookies, in the beginning of the event handleк list — unfortunately default eventEmitter of node doesn't support it and it might be not such a great idea to rearrange the list.
  2. change the way(the place where) the callback is executed. Right now request class attaches an on('response') listeneу when it is created if I move it to Request.prototype.end method all tests pass but they yield "double callback!" so I assume it's wrong.
@hallas
Copy link
Contributor

hallas commented Jan 28, 2014

can you provide a runnable example where it fails?

@vsuhanov
Copy link
Author

just put this file in a test/node folder. Or how want me to do it?

https://gist.github.com/vsuhanov/8665978

@hallas
Copy link
Contributor

hallas commented Jan 28, 2014

would be really great if it was something I could just copy paste and run with node :) nvm ill fix it my self

vsuhanov added a commit to vsuhanov/superagent that referenced this issue Apr 4, 2014
vsuhanov added a commit to vsuhanov/superagent that referenced this issue Apr 4, 2014
@veeti
Copy link

veeti commented Apr 10, 2014

Ping. Just spent a hour trying to figure out why this wasn't working just to find this issue.

@gjohnson
Copy link
Contributor

Hmm... I have not really messed with the agent additions much. Maybe @hunterloftis would have a thought or two before I dig in.

@rubenv
Copy link

rubenv commented Apr 10, 2014

Oh what a crappy bug, lost a lot of time on this one. While I don't have a patch for it, here's a way to work around it:

agent
    .post('/queue/4/status')                                                                                                                  
    .expect(200, status)
    .end(function (err) {
        process.nextTick(function () {                                                                                                        
            cb(err);                                                                                                                          
        });                                                                                                                                   
    });  

Running the callback in the next tick ensures that the next request will only happen once the cookies are set.

@vsuhanov
Copy link
Author

I made a pull request #354 with a possible solution.

But it fails travis build on node version 0.8 which appears to be a general issue right now I noticeв that all latest builds crash on it.

vsuhanov added a commit to vsuhanov/superagent that referenced this issue Apr 10, 2014
…lback.

the solution is rearranging event listeners of the Request making sure
that first listener is the one that sets cookies.

test included
alsotang added a commit to alsotang/superagent that referenced this issue Apr 23, 2014
…s now executed before users callback in .end()
@madhums
Copy link

madhums commented Jul 9, 2014

any updates on this?

@alsotang
Copy link

seems no. I think my fix is ok:

alsotang@bb47cd4

@ralyodio
Copy link

it still doesn't work for me.

@madhums
Copy link

madhums commented Aug 12, 2014

@alsotang the tests are failing #366.

@madhums
Copy link

madhums commented Aug 12, 2014

Oh nevermind, its in node 0.8

@alsotang
Copy link

@madhums okok, forget 0.8

@mocheng
Copy link

mocheng commented Aug 29, 2014

Hit by this bug.
It looks there is already quite a few PR available. Not merged yet?

@iammaart
Copy link
Contributor

+1
This bug is still present in v0.21.0.

vsuhanov added a commit to vsuhanov/superagent that referenced this issue Dec 11, 2014
…lback.

the solution is rearranging event listeners of the Request making sure
that first listener is the one that sets cookies.

test included

removed 0.8 node.js from travis config
@Dynasty9
Copy link

Dynasty9 commented Feb 5, 2015

+1 I've lost days to this.

@ilanbiala
Copy link

Has this been merged in and released?

@defunctzombie
Copy link
Contributor

I don't think it has. I will take a look this week.

@alexanderlperez
Copy link

+1

@alexhung
Copy link

Just lost like 4 hours on this. +1 on merging and release soon.

@defunctzombie
Copy link
Contributor

The PR needs to be reworked. I think we need a cleaner way to do it than the way the PR is doing it.

@elbuo8
Copy link

elbuo8 commented Mar 5, 2015

👍 to this.

@livin
Copy link

livin commented Mar 12, 2015

How it's possible that such an import bug is not yet fixed. Why this testing library is needed if it can't handle cookies at all. Struggled with it for enough time. Now thinking about replacing controller testing with something else. Perhaps e2e testing instead.

@defunctzombie
Copy link
Contributor

Fixed by 04a04e2

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

No branches or pull requests