socket: Resend messages on reconnect when the server never received them

(imported from commit 1810a76adf663e40c2d5292b48eb98553b47181d)
This commit is contained in:
Zev Benjamin
2013-11-18 18:07:06 -05:00
parent ddd3af0a36
commit 39c9ac79ae

View File

@@ -46,7 +46,8 @@ Socket.prototype = {
var req_id = this._next_req_id; var req_id = this._next_req_id;
var that = this; var that = this;
this._next_req_id++; this._next_req_id++;
this._requests[req_id] = {success: success, error: error}; this._requests[req_id] = {type: type, request: msg, success: success,
error: error};
this._requests[req_id].ack_timeout_id = setTimeout(function () { this._requests[req_id].ack_timeout_id = setTimeout(function () {
blueslip.info("Timeout on ACK for request " + req_id); blueslip.info("Timeout on ACK for request " + req_id);
that._try_to_reconnect(); that._try_to_reconnect();
@@ -61,6 +62,22 @@ Socket.prototype = {
return this._is_open && this._is_authenticated; return this._is_open && this._is_authenticated;
}, },
_resend: function Socket__resend(req_id) {
var req_info = this._requests[req_id];
if (req_info.ack_timeout_id !== null) {
clearTimeout(req_info.ack_timeout_id);
req_info.ack_timeout_id = null;
}
delete this._requests[req_id];
if (req_info.type !== 'request') {
blueslip.error("Cannot resend message of type: " + req_info.type);
return;
}
this.send(req_info.request, req_info.success, req_info.error);
},
_drain_queue: function Socket__drain_queue() { _drain_queue: function Socket__drain_queue() {
var that = this; var that = this;
var queue = this._send_queue; var queue = this._send_queue;
@@ -133,8 +150,7 @@ Socket.prototype = {
that._process_response(id, status.response); that._process_response(id, status.response);
} }
if (status.status === 'not_received') { if (status.status === 'not_received') {
that._process_response(id, {result: 'error', that._resend(id);
msg: 'Server has no record of request'});
} }
}); });
that._drain_queue(); that._drain_queue();