首页 文章

POST请求在Chrome上“停止”

提问于
浏览
3

我开始注意到发送到我们的应用服务器的发布请求在浏览器端停止了大约7秒钟,没有明显的原因 .

环境 :

  • Angular 1.4

  • Play Framework

  • Chrome 64. *

  • 服务器发送事件(SSE)

  • POST请求

从Chrome控制台看,TCP连接的数量在停止时大约为3-4,如网络 - >连接标识中所示

如果用户快速执行大约4个创建SSE订阅的UI操作,然后执行POST,则会始终观察到停止 .

我不是一个UI开发人员所以任何帮助调试都是有帮助的 .

3 回答

  • 1

    我也看过这个,使用Angular 1.4和Chrome(不确定是哪个版本) . 在我们的例子中,它似乎是由太多的并行请求引起的 . 因此,我们将请求分批捆绑 . 你可以使用这个功能,如果你喜欢它,看看它是否有助于你的情况:

    function _batchRequests(requests, batchSize) {
        function doBatch(batches, batchIndex, numBatches, deferred) {
            if (batchIndex === numBatches) {
                deferred.resolve();
                return null;
            }
            console.log('Doing batch ' + batchIndex);
            let p = [];
            let batch = batches[batchIndex];
            _.forEach(batch, (f) => {
                p.push(f());
            });
            return $q.all(p).then(() => {
                doBatch(batches, ++batchIndex, numBatches, deferred);
            }, (err) => {
                deferred.reject(err);
            });
        }
        let deferred = $q.defer();
        let b = batchSize || 3;
        let batches = _.chunk(requests, b);
        doBatch(batches, 0, batches.length, deferred);
        return deferred.promise;
    }
    

    请注意,上述函数取决于 _.chunk_.forEach 的lodash .

  • 1

    这非常相似

    Chrome stalls when making multiple requests to same resource?

    您可以尝试使帖子唯一,例如向查询添加一些随机数或尝试在播放端向响应添加 Headers Cache-Control: no-store

  • 0

    此问题已在Chrome 66及更高版本中得到解决 . 经历了很多发布文档,但无法确定导致或解决它的原因 .

相关问题