Comment 7 for bug 1190986

Revision history for this message
Raphaƫl Badin (rvb) wrote : Re: ERROR Nonce already used

There is no 'timestamp' column in the Nonce table so fixing this is not as easy as cleaning up the old nonces with a simple SQL query.

But I think I've got a solution that is both simple and doable without performing brain surgery on piston:
Let timestamp_threshold be the duration for which a nonce is valid (the value is in piston's codebase)
Every 5 minutes, run a script that does this:
  1. create a (fake) Nonce with token_key='', consumer_key='' and key=time.time()
  2.a. find the most recent Nonce (sort by id and take the nonce with the biggest id) with token_key='', consumer_key='' and key < time.time() - timestamp_threshold
  2.b. delete all the nonces which are older than the nonce fetched in 2.a., if any.

The idea is basically to create "checkpoint" nonces and then use them to clean up old nonces. The "checkpoint" nonces won't point to a customer so won't be considered by the oauth machinery. The Nonce.key field is a charfield with 255 which should be plenty to store a timestamp (storing a timestamp in a charfield is a bit hacky, I give you that, but it should work).