Hi, Looks like you never set a read timeout on the accepted socket, so your accepting socket will never time out when the client just 'goes away'.
https://github.com/apache/thrift/blob/19baeefd8c38d62085891d7956349601f79448b3/lib/java/src/org/apache/thrift/transport/TServerTransport.java#L41 On a separate note, you should just call server.serve() from within your server main()... Allen --- Terminal Musings: http://www.allengeorge.com/ Twitter: https://twitter.com/allenageorge/ Raft in Java: https://github.com/allengeorge/libraft/ Thrift Rust Bindings: https://thrift.apache.org On Sun, May 28, 2017 at 5:09 AM, Bryan Buchanan <[email protected]> wrote: > If a client that connects to a TThreadPoolServer goes away, when (if ever) > are threads returned to the pool. > > Note that in the example I've set the client socket timeout to zero so it > wait forever for a server response. If I press ^C on the client while the > server process is waiting for an input, the server process will never > "finish". > > > test.thrift > ------------- > namespace java com.webbtide.shared.thrift > > service TestApplication { > > string doSomething() > > } > > Client: Test.java > ------------------------ > public class Test { > > public static final int SOCKET_TIMEOUT = 0; > > public Test() { > > try { > > TTransport transport = new TSocket("192.168.5.1", 1200, > SOCKET_TIMEOUT); > transport.open(); > > TProtocol protocol = new TBinaryProtocol(transport); > TestApplication.Client client = new > TestApplication.Client(protocol); > > String s = ""; > do { > s = client.doSomething(); > System.err.println(s); > } while (!s.equalsIgnoreCase("quit")); > > } catch (TException ex) { > ex.printStackTrace(); > } > > } > > public static void main(String[] args) { > > new Test(); > } > > } > > Server implementation: > > public class TestApplicationRemoteImpl implements TestApplication.Iface { > > TestApplicationRemoteImpl() { > > super(); > > } > > @Override > public String doSomething() throws TException { > > System.err.println("[TestApplicationRemoteImpl.doSomething] start"); > > Console console = System.console(); > if (console == null) { > return "quit"; > } > > System.out.print("Enter something: "); > String s = console.readLine(); > > System.err.println("[TestApplicationRemoteImpl.doSomething] > finish"); > > return s; > } > } > > Server: > > public class TestApplicationRemoteServer { > > public static TestApplicationRemoteImpl handler; > public static TestApplication.Processor processor; > > public static void main(String[] args) { > > BasicConfigurator.configure(); > > try { > handler = new TestApplicationRemoteImpl(); > processor = new TestApplication.Processor(handler); > > Runnable simple = () -> { > simple(processor, 1200); > }; > new Thread(simple).start(); > System.err.println("[TestApplicationRemoteServer] started"); > > } catch (Exception ex) { > ex.printStackTrace(); > } > } > > public static void simple(TestApplication.Processor processor, int > port) { > try { > > TServerTransport serverTransport = new TServerSocket(port); > > // Use this for a multithreaded server > TServer server = new TThreadPoolServer(new > TThreadPoolServer.Args(serverTransport).processor(processor)); > System.out.println("Starting the server..."); > server.serve(); > } catch (TTransportException e) { > e.printStackTrace(); > } > } > > }
