Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java ConsoleApplication stops after calling the APIs after 60 seconds delay. #618

Closed
veryhungrycaterpillar opened this issue Feb 9, 2021 · 3 comments
Assignees
Labels

Comments

@veryhungrycaterpillar
Copy link

Bug Report

Describe the bug
I made Java ConsoleApplication for send PushMessage using line-bot-sdk-java.
After Sending PushMessage, Java process didn't stop.
Java process stopped 1 minutes later after sending.
Java process stopped soon if not sending.

To Reproduce

I send PushMessage by following code.

public void send(List<PushMessage> pushMessages) {

	if (pushMessages.isEmpty()) {
		return;
	}

	LineMessagingClient client = LineMessagingClient
			.builder(this.channelAccessToken)
			.build();

	for (PushMessage pushMessage : pushMessages) {
		try {
			BotApiResponse botApiResponse
					= client.pushMessage(pushMessage).get();
		} catch (InterruptedException | ExecutionException ex) {
			throw new RuntimeException(ex);
		}
	}
}

Expected behavior
Java process stops soon after sending.

Environment (please complete the following information):

  • OS: Windows10, CentOS 6.7 (64bit)
  • JDK Version oracle jdk-8u92
  • line-bot-sdk-java version(s) 4.3.0

Additional context
Does Response close in LineMessagingClientImpl?
https://github.com/line/line-bot-sdk-java/blob/master/line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingClientImpl.java

Retrofit added comment about close Response in 2020 May.
square/retrofit#3400

@kazuki-ma
Copy link
Contributor

Thank you for your reporting. I can reproduce the issue.

Looks like it's due to retrofit's internal executor service is based on user thread (not daemon thread),
It's blocks JVM shutdown.

@tokuhirom
Copy link
Member

https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html

OkHttpClient closes threads after about 60 seconds of idling.
It's unexpected behaviour, but it's not a serious bug.

import com.linecorp.bot.client.LineMessagingClient;
import com.linecorp.bot.model.response.BotInfoResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class MyApplication {
    private static final Logger log = LoggerFactory.getLogger(MyApplication.class);

    public static void main(String[] args) throws Exception {
        LineMessagingClient client = LineMessagingClient
                .builder("< channelAccessToken >")
                .build();

        BotInfoResponse botInfoResponse = client.getBotInfo().get();

        log.info("Got response: {}", botInfoResponse);
        long finished = System.currentTimeMillis();
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            log.info("Shutdown... after {} seconds delay",
                    (System.currentTimeMillis() - finished)/1000);
        }));
    }
}
18:57:46.242 [Thread-1] INFO MyApplication - Shutdown... after 60 seconds delay

line-bot-sdk-java should provide a way to call client.connectionPool().evictAll();.

@tokuhirom tokuhirom changed the title [BUG] Java ConsoleApplication doesn't stop after send PushMessage Java ConsoleApplication stops after calling the APIs after 60 seconds delay. Dec 8, 2021
@tokuhirom
Copy link
Member

This is a spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants