Discussion:
TSimpleServer.java does not stop when asked to...
Mario Emmenlauer
2017-07-13 13:04:20 UTC
Permalink
Dear All,

I have a Java TSimpleServer runnable in a thread running. The
main thread eventually asks the server to stop(). But they seem
to ignore the request. I checked the code of TSimpleServer.java
and I'm under the impression that the innermost loop the server
does not poll the variable stopped_ or does it?

https://github.com/apache/thrift/blob/master/lib/java/src/org/apache/thrift/server/TSimpleServer.java
[...] from line 76:

while (true) {
if (eventHandler_ != null) {
eventHandler_.processContext(connectionContext, inputTransport, outputTransport);
}
if(!processor.process(inputProtocol, outputProtocol)) {
break;
}
}

Do I understand correctly that the TSimpleServer will only check
stopped_ when there is no client connected? Personally I would
prefer if the client can not "force" my server to continue running.
If required, clients should be forcibly disconnected on stop().

Is there a way to achieve that? I found no methods "forceStop()" or
"disconnectClients()" or something like it. Am I even on the right
track?

All the best,

Mario Emmenlauer
Mario Emmenlauer
2017-07-13 18:10:48 UTC
Permalink
Ok, I found a bit more info myself, but still would need some help.
Post by Mario Emmenlauer
I have a Java TSimpleServer runnable in a thread running. The
main thread eventually asks the server to stop(). But they seem
to ignore the request. I checked the code of TSimpleServer.java
and I'm under the impression that the innermost loop the server
does not poll the variable stopped_ or does it?
https://github.com/apache/thrift/blob/master/lib/java/src/org/apache/thrift/server/TSimpleServer.java
while (true) {
if (eventHandler_ != null) {
eventHandler_.processContext(connectionContext, inputTransport, outputTransport);
}
if(!processor.process(inputProtocol, outputProtocol)) {
break;
}
}
I found that this loop is only interrupted if the client disconnects.
I tried changing 'while(true)' for 'while(!stopped_)' but that did
not help. I guess that one of the methods in the loop must be blocking.

Furthermore I found https://issues.apache.org/jira/browse/THRIFT-2441
'Cannot shutdown TThreadedServer when clients are still connected'
that seems to address exactly my issue! But it addresses only C++
code, not the Java servers, is that correct?

Should I open a new issue for this problem? Or am I on the wrong
track here?
Post by Mario Emmenlauer
Do I understand correctly that the TSimpleServer will only check
stopped_ when there is no client connected? Personally I would
prefer if the client can not "force" my server to continue running.
If required, clients should be forcibly disconnected on stop().
Is there a way to achieve that? I found no methods "forceStop()" or
"disconnectClients()" or something like it. Am I even on the right
track?
All the best,

Mario Emmenlauer
Mario Emmenlauer
2017-07-19 12:03:03 UTC
Permalink
Maybe my question is more a feature request or bug. So I've opened
a ticket for the problem here (in case other people want to follow
this up later):
https://issues.apache.org/jira/browse/THRIFT-4252

All the best,

Mario
Post by Mario Emmenlauer
Ok, I found a bit more info myself, but still would need some help.
Post by Mario Emmenlauer
I have a Java TSimpleServer runnable in a thread running. The
main thread eventually asks the server to stop(). But they seem
to ignore the request. I checked the code of TSimpleServer.java
and I'm under the impression that the innermost loop the server
does not poll the variable stopped_ or does it?
https://github.com/apache/thrift/blob/master/lib/java/src/org/apache/thrift/server/TSimpleServer.java
while (true) {
if (eventHandler_ != null) {
eventHandler_.processContext(connectionContext, inputTransport, outputTransport);
}
if(!processor.process(inputProtocol, outputProtocol)) {
break;
}
}
I found that this loop is only interrupted if the client disconnects.
I tried changing 'while(true)' for 'while(!stopped_)' but that did
not help. I guess that one of the methods in the loop must be blocking.
Furthermore I found https://issues.apache.org/jira/browse/THRIFT-2441
'Cannot shutdown TThreadedServer when clients are still connected'
that seems to address exactly my issue! But it addresses only C++
code, not the Java servers, is that correct?
Should I open a new issue for this problem? Or am I on the wrong
track here?
Post by Mario Emmenlauer
Do I understand correctly that the TSimpleServer will only check
stopped_ when there is no client connected? Personally I would
prefer if the client can not "force" my server to continue running.
If required, clients should be forcibly disconnected on stop().
Is there a way to achieve that? I found no methods "forceStop()" or
"disconnectClients()" or something like it. Am I even on the right
track?
Loading...