danwrong / restler

REST client library for node.js
MIT License
1.99k stars 391 forks source link

putJson in parallel #230

Open dei79 opened 8 years ago

dei79 commented 8 years ago

When I try to run putJson in parallel via promisses restler sends the payload of the last queued promise in all other request? Do I use the restler-API wrong or is it a concurrency issue?

theGrue commented 8 years ago

I've run into this myself too, but have had a hard time isolating it down to a single test. I haven't seen much discussion about it out there though, aside from a StackOverflow post that mentions it off-hand as a reason not to use Restler. (http://stackoverflow.com/questions/30112657/how-to-use-bluebird-to-promisify-node-rest-client)

dei79 commented 8 years ago

Did you found some solution or an other module which can do this? Do you have some hints so that I can try to find out what going on internally? Any comment from the core team about a workaround or something what could help?

theGrue commented 8 years ago

The thing that really gets me about this is that I have some code that can reproduce the problem every time, but it uses some private APIs so I can't share it. If I try to make an isolated version of the issue, it doesn't happen. But, if I hit the same private APIs with another HTTP library like https://github.com/mzabriskie/axios, I don't have the same issue. It's making it really tough to tell whether this is a Restler issue or an issue in the private API I'm making requests against.

theGrue commented 8 years ago

Okay, I think I've got something! As I mentioned before, this was a private API I was hitting, so I saved an "options" object for convenience containing the credentials necessary to use it. In my simple example, I had no such API key. So the root of the problem seems to be that if you pass the same options parameter to multiple putJson calls, they'll all end up sending the same request body! Any chance this fits with the case where you're seeing the issue?

RubenCordeiro commented 8 years ago

I also encountered the same issue. +1 for @theGrue pull request.

mmouterde commented 8 years ago

+1 for @theGrue pull request.