bitvavo / java-bitvavo-api

Java wrapper for the Bitvavo API
ISC License
9 stars 13 forks source link

Thread.sleep() -> IllegalArgumentException #7

Open l33th4x0rr opened 3 years ago

l33th4x0rr commented 3 years ago

Getting the following error shortly after starting a WebSocket:

Exception in thread "Thread-14" java.lang.IllegalArgumentException: timeout value is negative
    at java.base/java.lang.Thread.sleep(Native Method)
    at com.bitvavo.api.Bitvavo$2.run(Bitvavo.java:228)
    at java.base/java.lang.Thread.run(Thread.java:834)

The websocket itself is functioning properly, its just that this error gets thrown frequently. This is also happening randomly when the websocket has been running for some time.

l33th4x0rr commented 3 years ago

@joeri-vv ?

joeri-vv commented 3 years ago

Excuse me, this one slipped by. I am not able to reproduce this error. The difference between the rate limit reset and the current time should in theory never be negative. Could you please check your System.currentTimeMillis() against our time endpoint (which returns our server time)? On windows systems i've had the problem before where the clock would drift, and would require manual synchronisation with the windows servers. For now you can replace Thread.sleep(timeToWait); in line 198 of Bitvavo.java to:

if (timeToWait > 0) {
    Thread.sleep(timeToWait);
}

and rebuild through mvn clean install. If the ratelimitreset would be negative, the timeout is not required either, so it is fine to skip the sleep. Before pushing this update, i would like to know how you could get negative values. Please could you print the rateLimitReset and current time through System.currentTimeMillis(), while also noting the timestamp externally through a service like epoch converter. If this is simply because the roundtrip + execution time is larger than the timeout itself, this fix would be fine to push.