I tend to think that random intermittent problems are electrical and on a bike as complicated as a brick usually are in a connection. A connection can be in a connector or a switch, any place where two parts touch each other to let electrical current through.
The worst thing about intermittent stuff is that you never really know if you fixed the problem. All you can do is check and correct all the things that might cause your problem and hope for the best.
I would start by cleaning and making sure the four pin tank connector is tight and making good connection. You could try to test it by wiggling it when the engine is running. That connector is famous for causing problems, especially on bikes that show signs of neglect or have been kept outside for long periods.
Beyond that, you need to go through every connection on the bike cleaning and making sure it's tight.
If the problem persists, it is possible you have an electronic component that is beginning to fail. Normally, electronics that have not completely failed will start to give problems when they get hot, and stop acting up when they cool down. The best example of this is the Hall Effect Sensors on the front of the engine that trigger the ignition. The best way to check that type of problem is to warm up the bike with a ride, and when the problem appears use a freeze spray on the suspect part to see if the problem then goes away.
I doubt your problem is a failing part, those usually result in a shut down that lasts a ot longer than what you are seeing.