[ 
https://issues.apache.org/jira/browse/THRIFT-3156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15207452#comment-15207452
 ] 

Atsuhiro Suzuki edited comment on THRIFT-3156 at 3/22/16 10:40 PM:
-------------------------------------------------------------------

I am still new to node js and thrift so I may be wrong, but I think the problem 
lies in the connection.js file.

When a Connection is created,  "connect" and "secureConnect" event listeners 
are added.  When a connection in TLS is being made, both of these functions are 
triggered, and thus the "data" event is triggered twice.  When I commented 
either one of the event listeners, the double function execution did not occur.

I am still currently looking for solutions, and my temporary solution is to 
wrap each function call made by the client with a dummy thrift function because 
for some reason only the dummy function is called twice but the functions 
within it are only called once.

Ex (Added TLS connection to the example provided by Thrift):
client.dummy(1, function(err, response){
   console.log("This will be called twice on server side.  Result is: ", 
response);
  if (err) {
    console.error(err);
  }
  else {
    client.store(user, function(err, response) {
      if (err) {
        console.error(err);
      } else {
        console.log("client stored:", user.uid);
        client.retrieve(user.uid, function(err, responseUser) {
          if (err) {
            console.error(err);
          } else {
            console.log("client retrieved:", responseUser.uid);
            connection.end();
          }
        })
      }
    })
  }
});


was (Author: atsuzu):
I am still new to node js and thrift, but I think the problem lies in the 
connection.js file.

When a Connection is created,  "connect" and "secureConnect" event listeners 
are added.  When a connection in TLS is being made, both of these functions are 
triggered, and thus the "data" event is triggered twice.  When I commented 
either one of the event listeners, the double function execution did not occur.

I am still currently looking for solutions, and my temporary solution is to 
wrap each function call made by the client with a dummy thrift function because 
for some reason only the dummy function is called twice but the functions 
within it are only called once.

Ex (Added TLS connection to the example provided by Thrift):
client.dummy(1, function(err, response){
   console.log("This will be called twice on server side.  Result is: ", 
response);
  if (err) {
    console.error(err);
  }
  else {
    client.store(user, function(err, response) {
      if (err) {
        console.error(err);
      } else {
        console.log("client stored:", user.uid);
        client.retrieve(user.uid, function(err, responseUser) {
          if (err) {
            console.error(err);
          } else {
            console.log("client retrieved:", responseUser.uid);
            connection.end();
          }
        })
      }
    })
  }
});

> Node TLS: server executes processing logic two full times
> ---------------------------------------------------------
>
>                 Key: THRIFT-3156
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3156
>             Project: Thrift
>          Issue Type: Bug
>          Components: Node.js - Library
>         Environment: OS X w/ Node.js
>            Reporter: John Batte
>         Attachments: thrift-jira-evidence.zip
>
>
> h4. Using attached {{thrift-jira-evidence.zip}}
> {code}
> $ unzip thrift-jira-evidence.zip
> $ cd thrift-jira-evidence
> {code}
> *Note*: you'll need a total of three certs: {{ca.crt}}, {{server.crt}}, and 
> {{server.key}}. These have not been provided in the evidence. 
> h4. Server side reproduce steps
> # {{cd server}}
> # Copy {{ca.crt}} to {{config/ssl/ca.crt}}
> # Copy {{server.crt}} to {{config/ssl/server.crt}}
> # Copy {{server.key}} to {{config/ssl/server.key}}
> # {{npm install}}
> # {{NODE_DEBUG="tls" npm start}}
> h5. Server output after server start
> {code}
> > [email protected] start /your/path/to/server
> > node ./src/node/index.js
> Thrift service now listening on port 9797
> {code}
> h4. Client side reproduce steps
> # {{cd client}}
> # Copy {{ca.crt}} to {{config/ssl/ca.crt}}
> # {{npm install}}
> # {{NODE_DEBUG="tls" npm start}}
> h5. Client output after client start
> {code}
> > [email protected] start /your/path/to/client
> > node ./src/node/index.js
> Creating connection host: localhost port: 9797
> Creating client
> Sending: Hello, World!
> TLS 15599: secure established
> Response received!
> Killing connection
> Success! Hello, World! >> !dlroW ,olleH
> {code}
> h5. Server output after client start
> {code}
> TLS 15547: onhandshakestart
> TLS 15547: onhandshakedone
> TLS 15547: secure established
> Mapping to specific processor call
> Trace: Inside process_reverse
>     at TermReverserProcessor.process_reverse 
> (/your/path/to/server/src/node/contracts/TermReverser.js:196:11)
>     at TermReverserProcessor.process 
> (/your/path/to/server/src/node/contracts/TermReverser.js:183:39)
>     at /your/path/to/server/node_modules/thrift/lib/thrift/server.js:55:21
>     at TLSSocket.<anonymous> 
> (/your/path/to/server/node_modules/thrift/lib/thrift/transport.js:63:7)
>     at TLSSocket.emit (events.js:107:17)
>     at readableAddChunk (_stream_readable.js:163:16)
>     at TLSSocket.Readable.push (_stream_readable.js:126:10)
>     at TCP.onread (net.js:529:20)
> Reversing: Hello, World! call count 1
> Mapping to specific processor call
> Mapping to specific processor call
> Trace: Inside process_reverse
>     at TermReverserProcessor.process_reverse 
> (/your/path/to/server/src/node/contracts/TermReverser.js:196:11)
>     at TermReverserProcessor.process 
> (/your/path/to/server/src/node/contracts/TermReverser.js:183:39)
>     at /your/path/to/server/node_modules/thrift/lib/thrift/server.js:55:21
>     at TLSSocket.<anonymous> 
> (/your/path/to/server/node_modules/thrift/lib/thrift/transport.js:63:7)
>     at TLSSocket.emit (events.js:107:17)
>     at readableAddChunk (_stream_readable.js:163:16)
>     at TLSSocket.Readable.push (_stream_readable.js:126:10)
>     at TCP.onread (net.js:529:20)
> Reversing: Hello, World! call count 2
> Mapping to specific processor call
> {code}
> *Conclusion*: something is resetting the stream position to zero _after 
> server-side processing is complete_, causing a second complete execution to 
> occur, even though the client only receives one response. This issue does not 
> occur with the equivalent code when TLS has been "turned off". My colleagues 
> and I are having difficulty locating the errant code. Any help is appreciated.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to