cubicweb #837889 possible asyncRemoteExec race condition [resolved]

While meditating on the API, it occurred to me that a possible race condition could occur, like in:

var d = asyncRemoteExec(...);
// WHAT IF THE ANSWER IS ALREADY THERE ?
d.addCallback(...);

The original Mochikit implementation keeps track of the ajax call status (fired, success, error), so as to allow later callback/errback additions (if the response is already there, these callbacks are fired immediately).

The current implementation (see cubicweb.compat.js) does not seem to have such an internal state. The callback given to jQuery.ajax are immediately applied. If there are not callbacks yet, nothing will happen.

Note that it has been known for a while that some responses get lost (from time to time, in a non-deterministic way).

I'd like someone to review the code in question and confirm/infirm this interpretation.

Moreover, whatever the implementation details, I find the API to be at least troubling. It has been constructed as an homage to Twisted deferreds, which typically all run synchronously (in a select/poll loop), hence cannot suffer from such a race. It seems inappropriate to emulate such an API in a context of true concurrency.

priorityimportant
typebug
done in3.7.4
load0.500
load left0.000
closed by<not specified>