Inline function triggered by a callback = execution timeout
-
@Lindon which is based on your benchmark before not a very long time probably - I guess this is a case for @Christoph-Hart now :)
-
@Christoph-Hart is
findFiles
synchronous? -
I fiddled around a little more - its in and around the 200ms mark that its failing...sometimes it will make it over 200ms and be OK - but only slightly and very rarely...
-
Alright, I could reproduce the issue. The thing is that there are different timeout values for different callbacks, so the paint routine eg. has a very short timeout value because it's not expected to take longer than 200ms, and if you're writing a paint routine that takes longer than 200ms you'll need to take a step back and evaluate life decisions that led you to the point.
However the timeout is a single value and if you're calling something on another thread (like eg. the server thread), which has a much higher timeout to cope with things like findFiles() etc., it will overwrite the long timeout value with the short paint timeout restriction hence triggering the timeout pretty fast (and scanning 50-100 files quickly exceeds 200ms).
The complicated solution would be to make a thread local value for the timeout so that it won't cause problems like this, but actually I think I'll just forget about the entire concept of different timeouts and just use a single reasonable value like 3 seconds everywhere and then call it a day - the only hard reason for a timeout is to prevent
while(true) { Math.random(); }
from freezing your system and the idea of educating people by not allowing their code to run longer than an arbitrary limit isn't worth the hassle of coping with edge cases like this.
-
Alright, now everything has 5 seconds to complete its task - the only difference is that the
onInit
callback has a timeout that can be specified in the settings (defaults to 15 seconds).Also I've bypassed the timeout detection for the
findFiles()
call as this is a call that has a unbounded maximum execution time so you should be able to scan 10 thousands of files without breaking the timeout limit. -
@Christoph-Hart that's perfect. Thank you!