I was reading through the javascript code and came upon this:
/**
* Return the next message ref, accounting for overflows
* @returns {string}
*/
makeRef(){
let newRef = this.ref + 1
if(newRef === this.ref){ this.ref = 0 } else { this.ref = newRef }
return this.ref.toString()
}
(found here:
phoenix/socket.js at e221f88083779a4055bddf3d268f5d23f474bea9 · phoenixframework/phoenix · GitHub)
I was just wondering why the overflow protection is on there. I can see that this a good practice but in this case I cannot find any way of every reaching that overflow, or am I missing something?
Number.MAX_SAFE_INTEGER
// 9007199254740991
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
// true
Number.MAX_SAFE_INTEGER / 1000 / 24 / 60 / 60 / 365
// 285616.4147241562
So if you generate 1000s new refs per second you can still get 28 000 years in the future. Seems like a very long time to have 1 client running without ever crashing?