Merge pull request #1867 from matrix-org/luke/fix-group-request-concurrency
Prevent error responses wedging group request concurrency limit
This commit is contained in:
commit
3d478c3c3a
1 changed files with 16 additions and 17 deletions
|
@ -48,25 +48,24 @@ function checkBacklog() {
|
||||||
|
|
||||||
// Limit the maximum number of ongoing promises returned by fn to LIMIT and
|
// Limit the maximum number of ongoing promises returned by fn to LIMIT and
|
||||||
// use a FIFO queue to handle the backlog.
|
// use a FIFO queue to handle the backlog.
|
||||||
function limitConcurrency(fn) {
|
async function limitConcurrency(fn) {
|
||||||
return new Promise((resolve, reject) => {
|
if (ongoingRequestCount >= LIMIT) {
|
||||||
const item = () => {
|
// Enqueue this request for later execution
|
||||||
ongoingRequestCount++;
|
await new Promise((resolve, reject) => {
|
||||||
resolve();
|
backlogQueue.push(resolve);
|
||||||
};
|
});
|
||||||
if (ongoingRequestCount >= LIMIT) {
|
}
|
||||||
// Enqueue this request for later execution
|
|
||||||
backlogQueue.push(item);
|
ongoingRequestCount++;
|
||||||
} else {
|
try {
|
||||||
item();
|
return await fn();
|
||||||
}
|
} catch (err) {
|
||||||
})
|
// We explicitly do not handle the error here, but let it propogate.
|
||||||
.then(fn)
|
throw err;
|
||||||
.then((result) => {
|
} finally {
|
||||||
ongoingRequestCount--;
|
ongoingRequestCount--;
|
||||||
checkBacklog();
|
checkBacklog();
|
||||||
return result;
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue