Hello Akshar and Rattan!
So this looks more related to session timeouts than it does to session persistence. And adding the JSAPI to the situation makes everything more complicated.
The first question that tech support is going to ask, if you open a ticket about this (and I suggest you do) is: Does this happen when you access the view using the normal process (going through the Tableau Server GUI) instead of using JSAPI to render the view? If the answer to that is "No", then they will be unable to provide further support. JSAPI implementations are a more advanced use of Tableau Server, and is not fully covered by Tableau Support. They can make sure that basic JSAPI functionality works, but cannot help troubleshoot any custom code you created to display the dashboard.
So for your first test, try this same scenario in a normal Tableau Server session, and lets see if we still get the same error.
If you do get the same behavior in the normal Tableau Server interface, then this would most likely be related to the session idle timeout. This is controlled by the Tableau Server configuration key "wgserver.session.idle_limit". From the screenshot you posted, it looks like the idle timeout is set to 240 seconds, which explains why you can see this error as quickly as 5 minutes. Information on adjusting this timeout can be found at the page -> https://kb.tableau.com/articles/howto/changing-the-user-session-timeout
It looks like someone else may have already mentioned this link, but I don't see any news about what happened when you adjusted the timeout.
If you still get this behavior in the normal Tableau Server, even after adjusting the idle timeout, then I highly suggest that you open a Tableau support ticket so that we can check Tableau Server logs for the root cause of that "Unexpected Error" message.
I hope this info helps!
as per one of the suggestions i got on the question i had posted, I created a empty div and redeem a trusted ticket every 10 minutes and load the div which contains a image received from redeeming the trusted ticket.
If this is a session timeout issue:
Redeeming a trusted ticket will create a new session, but you really need to extend the life of the existing session. Change your code to request a small viz (or anything else from Tableau Server that requires a session), this will refresh the existing session.
If this is not a session timeout issue (if it happens after before the timeout interval):
Check your server logs to see if you can find the server error. Make a note of the time the failure occurred, and use the timestamp to help narrow down your search.