Please realize that it if the main relay is at fault, your fix “works” due to the opening and closing of the driver’s door and the time it takes to perform your gas cap ritual (i.e., it may be just as effective to get out of the car, walk to the rear, open the fuel door, do 25 push-ups, get back in and try starting it).