Hello All,

I am facing one interesting issue on windows while shutting down the windows 
server. I am using thrift patches 1031 and 1123 with 0.6.0 version of thrift.

here is the sequence of events:

After running server, I see that it is hosting the server as follows:

netstat -a -n -o | find "9090"
  TCP    0.0.0.0:9090           0.0.0.0:0              LISTENING       2752
  TCP    [::]:9090                  [::]:0                      LISTENING       
2752

After calling my server's fb303 shutdown call from a client,

Server prints following but does not come out of the loop:
Thrift: Tue Aug 30 10:31:24 2011 TServerSocket::interrupt() send() errno = 0

netstat -a -n -o | find "9090"
  TCP    0.0.0.0:9090           0.0.0.0:0              LISTENING       2752
  TCP    [::]:9090                  [::]:0                      LISTENING       
2752
  TCP    [::1]:49929            [::1]:9090             TIME_WAIT       0

After running the same shutdown call again, server comes out of the serve call 
and it stops successfully.

netstat -a -n -o | find "9090"
  TCP    [::1]:49929            [::1]:9090             TIME_WAIT       0
  TCP    [::1]:49930            [::1]:9090             TIME_WAIT       0


Question is why do I need to call shutdown twice on windows, while same thing 
on linux works in the first shutdown itself.

Following is the sequence of call stack:

Server is waiting in following call where server is of type TThreadPoolServer:
_server->serve();

Client calls following:
              boost::shared_ptr<TSocket> socket(new TSocket("localhost", 
i_port));
              boost::shared_ptr<TTransport> transport(new 
TBufferedTransport(socket));
              boost::shared_ptr<TProtocol> protocol(new 
TBinaryProtocol(transport));
              #ifdef WIN32
              TWinsockSingleton::create(); <=====using thrift patch 1031 and 
1123
              #endif
              MyServerClient client(protocol);
              transport->open();
              client.shutdown();
              transport->close();

Server gets a call in fb303's shutdown call which I have overloaded to call 
server's TThreadPoolServer::stop() function
  virtual void stop() {
    stop_ = true;
    serverTransport_->interrupt();
  }

Where above interrupt() call expands to following:

void TServerSocket::interrupt() {
  if (intSock1_ >= 0) {
    int8_t byte = 0;
    if (-1 == send(intSock1_, reinterpret_cast<const buffer_unit_t *>(byte), 
sizeof(int8_t), 0)) {
      GlobalOutput.perror("TServerSocket::interrupt() send() ", errno); 
<==================this gets printed as "Thrift: Tue Aug 30 10:31:24 2011 
TServerSocket::interrupt() send() errno = 0"
    }
  }
}

But only after the next call to shutdown(), it exists properly.


Any clue on this behavior?

Thanks,
~Deepak


Reply via email to