h2non / rocky

Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js (deprecated)
MIT License
371 stars 24 forks source link

Broken rocky#balance? #78

Closed kacperzuk closed 8 years ago

kacperzuk commented 8 years ago

I'm trying to make rocky#balance work, but even the example seems to work incorrectly. It returns:

Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1
Status: 200 from server: 1

While I expected something more like:

Status: 200 from server: 1
Status: 200 from server: 2
Status: 200 from server: 3
Status: 200 from server: 1
Status: 200 from server: 2
Status: 200 from server: 3
Status: 200 from server: 1
Status: 200 from server: 2
Status: 200 from server: 3
Status: 200 from server: 1

When I take the first server down, then it's even worse, as I only get Status: 502 from server: rocky, it never tries other (working) servers.

Is that an expected behavior?

h2non commented 8 years ago

That behavior is not expected. The issue was introduced in the latest release. I'll fix it asap.

Thank you for reporting.

kacperzuk commented 8 years ago

Here's my attempt of fixing this: https://github.com/kacperzuk/rocky/commit/2f82c6602e7dfa1fdcccc26e69055d888294ab03 .

I'm not sure it's the best way, but it passes tests and fixes the problem for me. I'll gladly make a PR if you think it's good enough.

h2non commented 8 years ago

Thanks for the proposal.

This is now fixed and properly tested in rocky@0.4.6. Feel free to update your dependency tree:

npm i rocky --force