fix: WebSocket flow control — bufferedAmount + threshold
Deploy loadtest / validate (push) Waiting to run

This commit is contained in:
2026-07-11 00:26:03 +04:00
parent bd38a68543
commit 4db96a6404
+25 -13
View File
@@ -209,31 +209,43 @@ function uploadFileWS(url, f, idx) {
ws.binaryType = 'arraybuffer'; ws.binaryType = 'arraybuffer';
ws.onopen = function () { ws.onopen = function () {
ws.bufferedAmountLowThreshold = CHUNK;
var reader = new FileReader(); var reader = new FileReader();
function sendNext() {
var end = Math.min(offset + CHUNK, f.size);
reader.readAsArrayBuffer(f.file.slice(offset, end));
}
reader.onload = function (e) { reader.onload = function (e) {
ws.send(e.target.result); ws.send(e.target.result);
offset += CHUNK; offset += CHUNK;
if (offset < f.size) {
var pct = Math.round(offset / f.size * 100); var pct = Math.round(offset / f.size * 100);
if (pct - lastProgress >= 10) { if (pct - lastProgress >= 5) {
lastProgress = pct; lastProgress = pct;
f.progress = pct; f.progress = pct;
renderTable(); renderTable();
} }
readNext();
} else { if (offset >= f.size) {
// Последний чанк + сигнал DONE // Когда буфер опустеет — шлём DONE
ws.send(e.target.result); function checkDone() {
if (ws.bufferedAmount === 0) {
ws.send('DONE'); ws.send('DONE');
f.progress = 100; } else {
renderTable(); setTimeout(checkDone, 50);
}
}
checkDone();
} }
}; };
function readNext() {
var end = Math.min(offset + CHUNK, f.size); ws.addEventListener('bufferedamountlow', function () {
reader.readAsArrayBuffer(f.file.slice(offset, end)); if (offset < f.size) sendNext();
} });
readNext();
sendNext();
}; };
ws.onmessage = function (e) { ws.onmessage = function (e) {