Some 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, then App2 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 like http://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 App1 shuts 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.
Leave a reply