Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
0.9.1
-
None
Description
hello,
I think there is a bug in nodejs client library when making concurent calls
my idl is:
struct Card { 1: required i32 id, 2: optional string name, } struct Player { 1: string name, 2: i32 actions, 3: i32 treasures, 4: i32 buys } typedef list<Card> Cardlist union ChooseReply { 1: Cardlist cards, 2: string special } struct ChooseOpt { 1: optional string msg, 2: optional Cardlist cards, 3: optional i32 nbcard, 4: optional string nbqualifier, 5: optional list<string> special } service Client { void showPlayerStatus(1: Player player), ChooseReply choose(1: ChooseOpt opt), }
for the server part:
from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from thrift.protocol import TJSONProtocol from thrift.server import TServer from client import Client from client.ttypes import * class ClientStub(object): def showPlayerStatus(self, player): print "showPlayerStatus called" print player def choose(self, opt): print "choose called" print opt if opt.cards and len(opt.cards) > 0: ret = ChooseReply(cards = opt.cards[-1:]) elif opt.special and len(opt.special) > 0: ret = ChooseReply(special = opt.special[-1]) print ret return ret def main(): handler = ClientStub() processor = Client.Processor(handler) transport = TSocket.TServerSocket(port = 9090) tfactory = TTransport.TBufferedTransportFactory() #pfactory = TJSONProtocol.TJSONProtocolFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) server.serve() if __name__ == "__main__": main()
and the client
"use strict"; var _ = require("underscore"); var Q = require("q"); var assert = require("assert"); var thrift = require('thrift'); var tjsonprotocol = require('./TJSONProtocol').TJSONProtocol; var Client = require('./gen-nodejs/Client') var ttypes = require('./gen-nodejs/client_types'); var ThriftUI = function(host, port) { this.connection = thrift.createConnection( host, port);//, {protocol: tjsonprotocol}); this.client = thrift.createClient(Client, this.connection); /* this.connection.on('error', function(err) { console.error(err); }); */ }; _.extend(ThriftUI.prototype, { showPlayerStatus : function(player) { console.log("showPlayerStatus"); var prom = Q.defer(); var thPlayer = new ttypes.Player({ }); _.extend(thPlayer, player); this.client.showPlayerStatus( thPlayer, function (err, resp) { console.log("choose done"); console.log("err", err); console.log("resp", resp); prom.resolve(); } ); //return prom.promise; }, choose : function (opt) { console.log("choose"); var prom = Q.defer(); var thOpt = new ttypes.ChooseOpt(opt); if (opt.cards !== undefined) { thOpt.cards = _.map(opt.cards, function(c) { return new ttypes.Card(c); }); } this.client.choose( thOpt, function (err, resp) { console.log("choose done"); console.log("err", err); console.log("resp", resp); prom.resolve(); } ); //return prom.promise; }, }); exports.ThriftUI = ThriftUI; var ui = new ThriftUI("127.0.0.1", 9090); ui.showPlayerStatus({name:"foo", actions:1, treasures:0, buys:1}); ui.choose({ msg:"lol", cards: [], special: ["EndTurn", "EndAction"] })
it produce randomly
hypnotoad% node ThriftUI.js showPlayerStatus choose choose done err null resp undefined choose done err null resp { cards: null, special: 'EndAction' } ^C hypnotoad% node ThriftUI.js showPlayerStatus choose choose done err null resp undefined choose done err null resp { cards: null, special: 'EndAction' } ^C hypnotoad% node ThriftUI.js showPlayerStatus choose choose done err null resp undefined ^C
Attachments
Issue Links
- duplicates
-
THRIFT-2068 Multiple calls from same connection are not processed in node
- Closed
-
THRIFT-1647 NodeJS BufferedTransport does not work beyond the hello-world example
- Closed