Jenkins linux agent hungs when connecting to controller


In my case, some agents show disconnected in my dashboard. However, when I check the log of that agent in Jenkins, it shows only a spinning cycle and nothing else. I found a workaround that can fix this which is to click configure, do nothing, click save, and relaunch the agent then it starts connecting and printing connect message.