[
https://issues.apache.org/jira/browse/THRIFT-2306?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henrique Mendonça closed THRIFT-2306.
-------------------------------------
Resolution: Duplicate
> concurent client calls with nodejs
> ----------------------------------
>
> Key: THRIFT-2306
> URL: https://issues.apache.org/jira/browse/THRIFT-2306
> Project: Thrift
> Issue Type: Bug
> Components: Node.js - Library
> Affects Versions: 0.9.1
> Reporter: Pierre Lamot
>
> hello,
> I think there is a bug in nodejs client library when making concurent calls
> my idl is:
> {code}
> 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),
> }
> {code}
> for the server part:
> {code}
> 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()
> {code}
> and the client
> {code}
> "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"]
> })
> {code}
> it produce randomly
> {code}
> 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
> {code}
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)