Grails: The Tomcat Kill Switch
Join the DZone community and get the full member experience.
Join For FreeSome time ago we had some strange effects when running an application in our local development environment. It turned out that the cause of these effects was a feature of the Grails Tomcat plugin.
The actual application consists out of two different Grails applications. To run both Grails applications at the same time on our local machines we configured two different application ports. The first application (let's call it App1) was running on Port 8081 while App2 (the second application) was running on Port 8082.
Now we faced the following effects:
- If App2 was started before App1 everything worked fine. However, if App1 was started first, thenApp2 would not start and show a "Port is already in use" error instead. What?!
- App1 contains links that point to App2. For our local environment these links look likehttp://localhost:8082/app2/someController. If App2 was not started at all and someone clicked one of these links App1 stopped working. What?!
After some research it turned out, that the reason for this is the TomcatKillSwitch provided by the Tomcat plugin. This class starts a server socket that listens on serverPort + 1. If something is send to this port the embedded tomcat is shut down.
So whenever we started App1 first the kill switch was listening at port 8082 (and therefore we were not able to start App2). Clicking any link that points to App2 triggered the kill switch and the embedded Tomcat of App1shuts down. If we started App2 first the server socket of the kill switch failed silently on startup of App1 and everything worked as expected. Changing the port of App2 from 8082 to 8083 solved the problem.
Published at DZone with permission of Michael Scharhag, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
-
VPN Architecture for Internal Networks
-
An Overview of Kubernetes Security Projects at KubeCon Europe 2023
-
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
Comments