Remove the pollInterval loop from SignalingServer.pollOffer in the standalone proxy
The constant pollInterval
is used in two places in the proxy code: in an outer loop that starts sessions, and in an inner loop for each session that repeatedly polls.
The design does not make sense: there should be only one place where the pollInterval
is enforced.
The inner loop, in the SignalingServer.pollOffer
function,
is barely even a loop at all:
all its internal code paths lead to a return
.
(The error case for s.Post
lacks a return
,
but an empty resp
will cause the following DecodePollResponse
check to return.)
The inner loop should be replaced with just one iteration of straight-line code.
I did some digging to find out how the code got to be this way.
Originally pollInterval
only appeared in the inner loop.
The outer loop would run as soon as the inner loop returned,
so the speed of the whole process depended on the delay being enforced by the inner loop.
There was a bug (#40055 (closed)) where the inner loop could return
without enforcing any delay (the same s.Post
case I mentioned above).
The fix in !51 (merged) was to add a delay to the outer loop as well.
Looking at the code now, it appears that the right place for the delay all along
was in the outer loop,
and it should not be in the inner loop at all.
Before 7a0428e3, the inner loop worked differently:
it was as if the s.Post
error case had a continue
rather than a return
.
That is why there is a loop at all in the inner loop.
7a0428e3 inadvertently changed it so that the inner loop
returned immediately, rather than enforcing a delay and running the loop again,
which was the actual cause of #40055 (closed), I think.