Coder Social home page Coder Social logo

Comments (11)

yeldarby avatar yeldarby commented on August 30, 2024

Suggested solution: use Date.now() instead; it's still a bit susceptible to servertime drift but should be Ok for most situations. I patched the library and it seems to be working Ok now both in my local and remote environments.

If you're using Ubuntu on EC2 make sure to install NTP

from coinbase.

mateodelnorte avatar mateodelnorte commented on August 30, 2024

Care to submit a pull request and a test case?

from coinbase.

mateodelnorte avatar mateodelnorte commented on August 30, 2024

So, the reason we moved to an hrtime() based approach was because Date.now() breaks down on a single machine where multiple requests happen faster than the precision of Date.now(): 6ee61e4

Have another suggestion that would work for both single machine and multi-machine cases?

from coinbase.

yeldarby avatar yeldarby commented on August 30, 2024

Possibly a multi-machine flag when you initialize it? For our use case we are doing low-frequency ops so millisecond time limits aren't a large issue.

You could also use an internal counter that increments after each api call. So something like Date.now()*1000+(counter++)%1000

I'm not sure why but date.now() was randomly failing with a 401 sometimes as well. Not sure if my change maybe didn't get one of the hrtime()s changed. 

We ended up giving each machine its own api key which works for now but will be a headache to automate if we want to, for instance, do autoscaling of our infrastructure in the future. 


Sent from Mailbox for iPhone

On Mon, Apr 14, 2014 at 8:51 AM, Matt Walters [email protected]
wrote:

So, the reason we moved to an hrtime() based approach was because Date.now() breaks down on a single machine where multiple requests happen faster than the precision of Date.now(): 6ee61e4

Have another suggestion that would work for both single machine and multi-machine cases?

Reply to this email directly or view it on GitHub:
#4 (comment)

from coinbase.

mateodelnorte avatar mateodelnorte commented on August 30, 2024

Are you sure you won't still have the same problem, essentially that you have two machines using the same algorithm to provide increasingly incremented values over time - but one machine thinks the current time is earlier than another?

The point of the new method was to give higher resolution, making it harder to have multiple calls between ticks. It sounds to me like your second machine is just sending an outdated nonce because the first is ahead of it.

Perhaps the solution is to ensure your servers are time synced: https://help.ubuntu.com/10.04/serverguide/NTP.html

from coinbase.

yeldarby avatar yeldarby commented on August 30, 2024

Yeah that was a suggestion for combining the new strategy with your need for more than one call per millisecond. 

Date.now() works if the servers' time is synced to within less than the precision of the time between calls (for us that is multiple seconds since it is triggered by a hit on a we page)

Sent from Mailbox for iPhone

On Mon, Apr 14, 2014 at 9:04 AM, Matt Walters [email protected]
wrote:

Are you sure you won't still have the same problem, essentially that you have two machines using the same algorithm to provide increasingly incremented values over time - but one machine thinks the current time is earlier than another?
The point of the new method was to give higher resolution, making it harder to have multiple calls between ticks. It sounds to me like your second machine is just sending an outdated nonce because the first is ahead of it.

Perhaps the solution is to ensure your servers are time synced: https://help.ubuntu.com/10.04/serverguide/NTP.html

Reply to this email directly or view it on GitHub:
#4 (comment)

from coinbase.

mateodelnorte avatar mateodelnorte commented on August 30, 2024

If you've got a branch you'd like me to look at, shoot me a link or make a PR.

from coinbase.

pwlmaciejewski avatar pwlmaciejewski commented on August 30, 2024

@mateodelnorte I've stumbled upon an issue where two synced servers gave me two totally different values of process.hrtime. In docs you can read that it returns timestamp which is "relative to an arbitrary time in the past". My question is: are you sure this is the right usage of process.hrtime? For me it sounds like it should be used for benchmarking only.

from coinbase.

pwlmaciejewski avatar pwlmaciejewski commented on August 30, 2024

BTW I've tested the @yeldarby's solution and it works fine for me. #5 👍

from coinbase.

mateodelnorte avatar mateodelnorte commented on August 30, 2024

@fragphace, @yeldarby take a comments in #5. If the changes in https://github.com/mateodelnorte/coinbase/tree/feature/enhanced-nonce work for you, I'll bump version, push to master, and publish asap.

Thx.

from coinbase.

mateodelnorte avatar mateodelnorte commented on August 30, 2024

Closing. Fixed by #7

from coinbase.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.