Theme import Option doesn't work sometimes

Install option in admin customization for themes is sometime giving 502. But the file is being uploaded. The success rate is only 50%. What might be reasons for such behavior and how to avoid this ?