当接收到一个请求没有任何反应,会发生什么?我看到重试 [英] What happens when no response is received for a request? I'm seeing retries

查看:141
本文介绍了当接收到一个请求没有任何反应,会发生什么?我看到重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题可能更多的是浏览器有关的问题,我想,但它的一个pretty的根本的一条,我想找到答案太为我冒险进入构建Web应用程序。

The question I have is probably more of a browser related question I think, but its a pretty fundamental one I'd like to find the answer too as I venture into building a web application.

在我的客户端code我做的 $。阿贾克斯通话。这个帖子可能需要一段时间来作出回应。我所看到的是经过一定的时间的请求被重新发送。

In my client side code I am doing an $.ajax call. This Post can take a while to respond. What I'm seeing is after a certain amount of time the request is being send again.

我还以为是我的 $。阿贾克斯电话再次发送,但不管多少次,我在服务器上看到POST请求,我只看到了 beforeSend 回调调用一次。我相当确信我的code不能发送超过一次,所以我觉得它在浏览器中重试?

I thought it was my $.ajax call sending it again, but no matter how many times I see the POST request on the server, I only see the beforeSend callback called once. I am fairly sure my code isn't sending it more than once, so I think its the browser retrying?

我知道我的服务器越来越请求超过一次,我跑了Wireshark的,可以看到POST请求多次。所以,我的假设是,这是事做HTTP?也就是说,如果响应是不是一个特定量的时间内接收,然后该请求被重新发送?

I know my server is getting the request more then once as I ran up Wireshark and can see the post request multiple times. So my assumption is this is something to do with HTTP? I.e., if a response isn't received within a certain amount of time then the request is resent?

下面是低于我的电话的样本。

Here is a sample of my call below.

$.ajax({
                    async: false,
                    type: 'POST',
                    url: '<%= url_for('importDevice') %>',
                    data: { device: val },
                    retryLimit: 0,
                    //callback
                    success: function(data) {
                    alert('calling import');
                    if ( data == 'nomaster')
                    {
                            // Display a warning  toast, with a title
                            toastr.warning('You must set the Master Key first!', 'Warning');
                            $.ismasterset = false;
                            //reset the form contents after added
                    } else
                    {
                            $("div#content").html(data);
                    }
                    },
                     beforeSend: function(){
                    alert('in before send');
                    }
            });

这是所有的相应和code,'retryLimit不被使用,我只是还没有从我的code删除,并是这一问题在那里之前,我把它放在

This is all of the relevent code, 'retryLimit' isn't being used, I just haven't removed it from my code and yes the problem was there before I put it in.

编有来自客户端和服务器的输出。

EDITED with output from client and server.

确定我安装了活HTTP标头Firefox的。

ok I installed 'Live Http headers for Firefox'.

在生成器选项卡中我看到了一个单一的通话

In the 'Generator' tab I see the one single call

'#request# POST http://testhost/importdevice' 

我没有看到帖子里的头部分,虽然,也许那是因为没有反应?

I don't see the POST in the 'headers' section though, maybe thats because there's no response?

在我的网络服务器虽然我看到2个电话约22秒钟的时间间隔。

In my webserver though I see 2 calls about 22 seconds apart.

[太阳1月13日三时零八分45秒2013] [调试] POST / importdevice(Mozilla的/ 5.0(Macintosh电脑;英特尔的Mac OS X 10.8; RV:17.0)的Gecko / 20100101火狐/ 17.0)。

[Sun Jan 13 03:08:45 2013] [debug] POST /importdevice (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0).

[太阳1月13日三时09分07秒2013] [调试] POST / importdevice(Mozilla的/ 5.0(Macintosh电脑;英特尔的Mac OS X 10.8; RV:17.0)的Gecko / 20100101火狐/ 17.0)。

[Sun Jan 13 03:09:07 2013] [debug] POST /importdevice (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0).

我还可以看到在Wireshark的......

I can also see these same calls in wireshark...

这就是为什么我是问,如果这是正常的行为,试图重新发送请求,如果响应不回来,以类似的方式到TCP握手和SYN重传。

This is why I was asking if this is normal behaviour to try to resend the request if a response doesn't come back, in a similar fashion to a TCP handshake and the SYN retransmission.

新的更新

这似乎并不具有任何与我Ajax调用。如果我创建一个简单的HREF一个按钮。

It doesn't seem to have anything to do with my Ajax call. If I create a button with a simple HREF.

即     A HREF =/ importdevice?设备= serverA的类=BTN BTN-成功> TestDirect

然后在我的活HTTP头输出我得到...只是一个实例。

i.e "a href="/importdevice?device=serverA" class="btn btn-success">TestDirect

Then in my 'Live HTTP headers output I get... just one instance.

#request# GET http://172.16.118.15/importdevice?device=serverA

但同样在我的服务器日志,一旦我得到。

But once again in my server logs I get.

[Sun Jan 13 03:20:25 2013] [debug] GET /importdevice (Mozilla/5.0 (Macintosh; Intel Mac OS  X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0).
[Sun Jan 13 03:20:48 2013] [debug] GET /importdevice (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0).

而在Wireshark的服务器

And in wireshark on the server

我看到它的两倍,以及...和预期我的服务器code调用两次太...这实在是令人困惑了我。

I'm seeing it twice as well... and as expected my server code is called twice too... This is REALLY confusing to me.

推荐答案

签出这篇博客文章,解释所发生的事情: http://geek.starbean.net/?p=393

Checkout this blog post that explains what is happening: http://geek.starbean.net/?p=393

根据HTTP / 1.1 RFC 8.2.4:

According to HTTP/1.1 RFC 8.2.4:

如果一个HTTP / 1.1客户端发送包括一个请求主体的请求,但不包括一个Expect请求头域与100-继续期望,并且如果客户端不直接连接到HTTP / 1.1原始服务器,如果客户看到的连接关闭从服务器接收任何地位之前,客户端应该重新尝试这个请求。

If an HTTP/1.1 client sends a request which includes a request body, but which does not include an Expect request-header field with the "100-continue" expectation, and if the client is not directly connected to an HTTP/1.1 origin server, and if the client sees the connection close before receiving any status from the server, the client SHOULD retry the request.

请确保你设计你的web应用程序容忍这些额外的请求。如果你想Ajax请求做一些事情只有一次,如写东西到数据库,那么你需要设计的要求,因为幂等。请参阅:什么是幂等操作

Make sure you design your web app to tolerate these extra requests. And if you want the ajax request to do something only once, such as writing something to a database, then you need to design the request as idempotent. See: What is an idempotent operation?

此外,这突出GET和POST操作之间的差异: <一href="http://www.cs.tut.fi/~jkorpela/forms/methods.html">http://www.cs.tut.fi/~jkorpela/forms/methods.html

Also, this highlights the differences between GET and POST operations: http://www.cs.tut.fi/~jkorpela/forms/methods.html

作为一般的设计实践:
-GET操作应设计为幂等
-POST操作应该用于写入数据库等。

As a general design practice:
-GET operations should be designed as idempotent
-POST operations should be used for writing to databases, etc.

这篇关于当接收到一个请求没有任何反应,会发生什么?我看到重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆