Search code examples
javatomcatspring-boot-actuatorhttp-status-code-503

How can I produce a 503 error locally with Tomcat?


I am working on a project developed with Spring Boot using version 8.5.9 of Tomcat.

The application offers RESTfull web services in JAX RS. In the Prod environment, sometimes I get an error 503 Service not available, but I can not reproduce it because I use my local Mock.

Is there a way to reproduce the error locally? Like putting the TomCat on hold in unavailable for a moment?


Solution

  • According to the MDN, HTTP 503 Service Unavailable server error means :

    ... response code indicates that the server is not ready to handle the request.

    The common causes are :

    a server that is down for maintenance or that is overloaded.

    To reproduce this error response in a natural way, you could so overloaded Tomcat.

    To do it change the maximum number of simultaneous requests that can be handled by Tomcat.

    If you use an embedded tomcat, set the server.tomcat.max-threads Spring Boot property with a weak value easily reachable such as :

    server.tomcat.max-threads = 1
    

    Otherwise, if you use our own Tomcat installation, set maxThreads with a weak value in the Connector element of the server.xml configuration file :

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               ...
               maxThreads="1"/>