lukabers lukabers - 4 months ago 26
AngularJS Question

Double $http.post in angularJS

we are using $http.post to send a request to our server and when the server doesn't reply in time (approx 3 secs) our angularjs client send another http.post. We have tracked this with tcpdump and we see 2 different $http.post.

This is our controller:

var request = Local.testPost();
request.then(function successCallback(response) {
console.log(response);
}, function errorCallback(error) {
console.log(error);
});


And this is our Local Service post:

this.testPost = function(){
var data = 'token='+User.getToken();

var request = $http(
{
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
url: self.server+'/api/cmd',
data: data
}
);
return request;
};


Our server logs 2 different post too...

How is possibile?
Thanks everybody!

UPDATE: Tcpdump Log

16:53:38.058379 IP 192.168.1.66.52515 > 8.ip-xxxxxx.eu.http: Flags [P.], seq 581:1162, ack 355, win 4106, options [nop,nop,TS val 206302095 ecr 194158267], length 581: HTTP: POST /api/cmd HTTP/1.1

16:53:41.843608 IP 192.168.1.66.52515 > 8.ip-xxxxx.eu.http: Flags [.], ack 709, win 4095, options [nop,nop,TS val 206305864 ecr 194161726], length 0

16:53:41.848302 IP 192.168.1.66.52515 > 8.ip-xxxxx.eu.http: Flags [F.], seq 1162, ack 709, win 4096, options [nop,nop,TS val 206305868 ecr 194161726], length 0

16:53:41.848918 IP 192.168.1.66.52522 > 8.ip-xxxxxx.eu.http: Flags [S], seq 4161058194, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 206305868 ecr 0,sackOK,eol], length 0

16:53:41.884020 IP 192.168.1.66.52522 > 8.ip-xxxxxxx.eu.http: Flags [.], ack 3569763921, win 4117, options [nop,nop,TS val 206305903 ecr 194161768], length 0

16:53:41.884246 IP 192.168.1.66.52522 > 8.ip-xxxxxx.eu.http: Flags [P.], seq 0:581, ack 1, win 4117, options [nop,nop,TS val 206305903 ecr 194161768], length 581: HTTP: POST /api/cmd HTTP/1.1

16:53:41.884701 IP 192.168.1.66.52515 > 8.ip-xxxxxx.eu.http: Flags [.], ack 710, win 4096, options [nop,nop,TS val 206305903 ecr 194161768], length 0

16:53:45.629884 IP 192.168.1.66.52522 > 8.ip-xxxxxx.eu.http: Flags [.], ack 355, win 4106, options [nop,nop,TS val 206309616 ecr 194162704], length 0

16:53:54.452688 IP 192.168.1.66.52435 > 8.ip-xxxxxx.eu.http: Flags [.], ack 5234, win 4096, options [nop,nop,TS val 206318403 ecr 194164846], length 0

16:53:54.452696 IP 192.168.1.66.52435 > 8.ip-xxxxxx.eu.http: Flags [.], ack 5234, win 4096, options [nop,nop,TS val 206318403 ecr 194164846], length 0

16:53:54.452719 IP 192.168.1.66.52435 > 8.ip-xxxxxx.eu.http: Flags [F.], seq 1261, ack 5234, win 4096, options [nop,nop,TS val 206318403 ecr 194164846], length 0

Answer

one possible cause could be if your server responds with 408 status, in this case some retry automatically run. You should not respond 408 if it's not a "real" 408.

have a look at this: https://github.com/angular/angular.js/issues/4806

cheers