springboot application shutsdown automatically on ec2

给你一囗甜甜゛ 提交于 2021-01-28 11:23:11

问题


I deployed my springboot application on ec2 (ubuntu as t2.medium size, AWS AMI as t3.medium size)

In my local pc, there is no problem.. but on the ec2, after few hours (during I dont work) It died by itself

I just wanted to check what happened when shutdown so I made a below java class as ContextClosedHandler.. but It seems no help for me

@Component
public class ContextClosedHandler implements ApplicationListener<ContextClosedEvent> {

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        LOGGER.info(event.getSource());
        LOGGER.info(event.getApplicationContext().getApplicationName());
        LOGGER.info(event.getApplicationContext().getDisplayName());
        LOGGER.info(event.getApplicationContext().getId());
        LOGGER.info(event.getApplicationContext().getParent());
        LOGGER.info(event.getApplicationContext().getStartupDate());
    }
}

and the log is like below

[INFO / 20201112 14:19 / http-nio-8080-exec-1 / Caller+0         at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:175)
Caller+1         at org.apache.juli.logging.DirectJDKLog.info(DirectJDKLog.java:121)
Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]
        at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:560)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

[INFO / 20201112 14:51 / http-nio-8080-exec-2 / Caller+0         at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)
Caller+1         at org.apache.juli.logging.DirectJDKLog.info(DirectJDKLog.java:116)
Initializing Spring DispatcherServlet 'dispatcherServlet'

[INFO / 20201112 14:51 / http-nio-8080-exec-2 / Caller+0         at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:525)
Caller+1         at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:170)
Initializing Servlet 'dispatcherServlet'

[INFO / 20201112 14:51 / http-nio-8080-exec-2 / Caller+0         at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:547)
Caller+1         at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:170)
Completed initialization in 9 ms

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:26)
Caller+1         at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:12)
event.getSource(): org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4c203ea1, started on Thu Nov 12 11:56:20 UTC 2020

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:27)
Caller+1         at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:12)
event.getApplicationContext().getApplicationName(): 

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:30)
Caller+1         at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:12)
event.getApplicationContext().getDisplayName(): org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4c203ea1

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:32)
Caller+1         at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:12)
event.getApplicationContext().getId(): application

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:33)
Caller+1         at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:12)
event.getApplicationContext().getParent(): null

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:36)
Caller+1         at kr.co.motov.ssp.util.ContextClosedHandler.onApplicationEvent(ContextClosedHandler.java:12)
event.getApplicationContext().getStartupDate(): 1605182180002

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.shutdown(ExecutorConfigurationSupport.java:218)
Caller+1         at org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.destroy(ExecutorConfigurationSupport.java:208)
Shutting down ExecutorService 'scheduler'

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.shutdown(ExecutorConfigurationSupport.java:218)
Caller+1         at org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.destroy(ExecutorConfigurationSupport.java:208)
Shutting down ExecutorService 'executor'

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at com.zaxxer.hikari.HikariDataSource.close(HikariDataSource.java:350)
Caller+1         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
HikariPool-1 - Shutdown initiated...

[INFO / 20201112 15:19 / SpringContextShutdownHook / Caller+0    at com.zaxxer.hikari.HikariDataSource.close(HikariDataSource.java:352)
Caller+1         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
HikariPool-1 - Shutdown completed.

回答1:


The reason It automatically shutdowns is to logout ssh session on the shell.
so, I just executed my application with nohup command for executing as background.

nohup java -jar my-application.jar &

and if I deploy it using docker, there is no issue.




回答2:


The problem is not really about the application shutting down by itself but people trying to find security vulnerabilities on your application by sending forged requests. You can try to solve it by filtering the requests through a web server (like Apache Httpd) before forwarding them to the Spring Boot application.



来源:https://stackoverflow.com/questions/64814622/springboot-application-shutsdown-automatically-on-ec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!