kraih/mojo — pull request #644 by powerman (2014-07-12 00:40:48+00:00)
Title: Leaking stream while adding to keep-alive queue in Mojo::UserAgent

If `_enqueue()` call `_remove()`, which in turn call `_dequeue()`, then `$queue in _enqueue()` became detached from real queue in `$self` because `_dequeue()` will replace queue in `$self`. Which result in `_enqueue()` add new item not into real queue in `$self` but into detached `$queue`, and then losing it when `_enqueue()` returns. As side effect this "lost" connection won't be removed from ioloop when `$ua` destroyed, and it inactive_timeout will fire later, trying to call `_error()` and `_finish()` on undefined value:
```
$ prove -bv t/mojo/user_agent.t
...
ok 151 - right status
ok 152 - right content
Can't call method "_error" on an undefined value at /home/powerman/proj/perl/mojo/blib/lib/Mojo/UserAgent.pm line 111.
Can't call method "_finish" on an undefined value at /home/powerman/proj/perl/mojo/blib/lib/Mojo/UserAgent.pm line 112.
Can't call method "_error" on an undefined value at /home/powerman/proj/perl/mojo/blib/lib/Mojo/UserAgent.pm line 111.
Can't call method "_finish" on an undefined value at /home/powerman/proj/perl/mojo/blib/lib/Mojo/UserAgent.pm line 112.
not ok 153 - no streams leaked because inactivity_timeout not happens
```