You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/06 00:58:15 UTC

[GitHub] [pulsar] labuladong opened a new issue, #17480: [Bug][Java client] main thread won't exit if not close pulsar client

labuladong opened a new issue, #17480:
URL: https://github.com/apache/pulsar/issues/17480

   ### Search before asking
   
   - [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
   
   
   ### Version
   
   macOS 12.5.1 
   
   Pulsar 2.10.1
   
   Pulsar Java client 2.10.1
   
   ### Minimal reproduce step
   
   Run this snippet:
   
   ```java
   public class Main {
       public static void main(String[] args) throws PulsarClientException {
           PulsarClient client = PulsarClient.builder()
                   .serviceUrl("pulsar://localhost:6650")
                   .build();
   
           System.out.println("hello world"); // print successfully
           // without client.close(), `main` will be hanging, never exit
       }
   }
   ```
   
   
   ### What did you expect to see?
   
   Print `hello world` then exit normally.
   
   ### What did you see instead?
   
   Print `hello world` but never exit.
   
   ### Anything else?
   
   I know I should always `close` the client manually. But if I don't close it, is hanging to be the expected behavior?
   
   ### Are you willing to submit a PR?
   
   - [X] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] nicoloboschi commented on issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

Posted by GitBox <gi...@apache.org>.
nicoloboschi commented on issue #17480:
URL: https://github.com/apache/pulsar/issues/17480#issuecomment-1237964085

   @labuladong if you close the Pulsar client (`client.close()`) the process exits? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] labuladong closed issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

Posted by GitBox <gi...@apache.org>.
labuladong closed issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client
URL: https://github.com/apache/pulsar/issues/17480


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] labuladong commented on issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

Posted by GitBox <gi...@apache.org>.
labuladong commented on issue #17480:
URL: https://github.com/apache/pulsar/issues/17480#issuecomment-1238819175

   > @labuladong if you close the Pulsar client (`client.close()`) the process exits?
   
   Yes, it will.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] lhotari commented on issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

Posted by GitBox <gi...@apache.org>.
lhotari commented on issue #17480:
URL: https://github.com/apache/pulsar/issues/17480#issuecomment-1237979028

   > We (+ @yaalsn) discuss this, seems that netty has a shutdown hook to prevent client exit.
   
   Live non-daemon threads are a common reason why normal shutdown doesn't happen in a Java application.
   
   The [javadoc of java.lang.Thread](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html):
   
   >  When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:
   > 
   > * The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
   > * All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
   
   I believe that Pulsar client creates threads that are non-daemon threads. This might be intentional. 
   I assume that it's better to handle the shutdown in a controlled way in any case. 
   A simple fix to your problem is to add a shutdown hook that calls `client.close()`. 
   
   @labuladong What is your actual use case? Could you share more of the scenario that you have in mind?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] labuladong commented on issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

Posted by GitBox <gi...@apache.org>.
labuladong commented on issue #17480:
URL: https://github.com/apache/pulsar/issues/17480#issuecomment-1237556067

   We (+ @yaalsn) discuss this, seems that netty has a shutdown hook to prevent client exit.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] labuladong commented on issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

Posted by GitBox <gi...@apache.org>.
labuladong commented on issue #17480:
URL: https://github.com/apache/pulsar/issues/17480#issuecomment-1238819273

   @lhotari Hi, I'm just curious about how to exit even if missing `client.close()`. Now I figured it out from your answer. Thanks a lot!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org