Try this on for size. 2017-03-23 15:42 GMT+01:00 Randy Abernethy (JIRA) <[email protected]>:
> > [ https://issues.apache.org/jira/browse/THRIFT-4131?page= > com.atlassian.jira.plugin.system.issuetabpanels:comment- > tabpanel&focusedCommentId=15938478#comment-15938478 ] > > Randy Abernethy commented on THRIFT-4131: > ----------------------------------------- > > Would be great to get the patch, please attach (or if you prefer a pull > request is fine too). > > > Javascript with WebSocket handles oneway methods wrong > > ------------------------------------------------------ > > > > Key: THRIFT-4131 > > URL: https://issues.apache.org/jira/browse/THRIFT-4131 > > Project: Thrift > > Issue Type: Bug > > Components: JavaScript - Compiler, JavaScript - Library > > Affects Versions: 0.10.0 > > Environment: all > > Reporter: Martin Hejnfelt > > Assignee: Randy Abernethy > > Priority: Blocker > > > > When using the WebSocket transport all client->server calls install a > callback, and we depend on these callbacks being push()'ed and shift()'ed > sequentially, however, oneway methods never gets a reply, and therefore the > installed callback doesn't get removed, causing the callback array to get > "out of synchronization" so to speak, and subsequent calls, now deal with > the wrong callbacks, as data comes in. > > To remedy this I changed the compiler/generator to send a null callback > to the transport->flush method for oneway methods, and then in the > WebSocket transport code, make a null check and only install defined > callbacks. This seem to fix it for me. I can send in patches if necessary. > > > > -- > This message was sent by Atlassian JIRA > (v6.3.15#6346) > -- Martin Hejnfelt
From 1212ad6e3d124a753cf062617e78275beb4bb9f1 Mon Sep 17 00:00:00 2001 From: Martin Hejnfelt <[email protected]> Date: Thu, 23 Mar 2017 15:55:36 +0100 Subject: [PATCH] js: WebSocket: Fix handling oneway methods --- compiler/cpp/src/thrift/generate/t_js_generator.cc | 24 +++++++++++++--------- lib/js/src/thrift.js | 16 ++++++++------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/compiler/cpp/src/thrift/generate/t_js_generator.cc b/compiler/cpp/src/thrift/generate/t_js_generator.cc index 985ee0c..b567181 100644 --- a/compiler/cpp/src/thrift/generate/t_js_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_js_generator.cc @@ -1501,16 +1501,20 @@ void t_js_generator::generate_service_client(t_service* tservice) { f_service_ << indent() << "return this.output.getTransport().flush(callback);" << endl; } else { f_service_ << indent() << "if (callback) {" << endl; - f_service_ << indent() << " var self = this;" << endl; - f_service_ << indent() << " this.output.getTransport().flush(true, function() {" << endl; - f_service_ << indent() << " var result = null;" << endl; - f_service_ << indent() << " try {" << endl; - f_service_ << indent() << " result = self.recv_" << funname << "();" << endl; - f_service_ << indent() << " } catch (e) {" << endl; - f_service_ << indent() << " result = e;" << endl; - f_service_ << indent() << " }" << endl; - f_service_ << indent() << " callback(result);" << endl; - f_service_ << indent() << " });" << endl; + if((*f_iter)->is_oneway()) { + f_service_ << indent() << " this.output.getTransport().flush(true, null);" << endl; + } else { + f_service_ << indent() << " var self = this;" << endl; + f_service_ << indent() << " this.output.getTransport().flush(true, function() {" << endl; + f_service_ << indent() << " var result = null;" << endl; + f_service_ << indent() << " try {" << endl; + f_service_ << indent() << " result = self.recv_" << funname << "();" << endl; + f_service_ << indent() << " } catch (e) {" << endl; + f_service_ << indent() << " result = e;" << endl; + f_service_ << indent() << " }" << endl; + f_service_ << indent() << " callback(result);" << endl; + f_service_ << indent() << " });" << endl; + } f_service_ << indent() << "} else {" << endl; f_service_ << indent() << " return this.output.getTransport().flush();" << endl; f_service_ << indent() << "}" << endl; diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js index 3ea57c8..3966d97 100644 --- a/lib/js/src/thrift.js +++ b/lib/js/src/thrift.js @@ -568,13 +568,15 @@ Thrift.TWebSocketTransport.prototype = { if (this.isOpen()) { //Send data and register a callback to invoke the client callback this.socket.send(this.send_buf); - this.callbacks.push((function() { - var clientCallback = callback; - return function(msg) { - self.setRecvBuffer(msg); - clientCallback(); - }; - }())); + if(callback) { + this.callbacks.push((function() { + var clientCallback = callback; + return function(msg) { + self.setRecvBuffer(msg); + clientCallback(); + }; + }())); + } } else { //Queue the send to go out __onOpen this.send_pending.push({ -- 2.1.4
