It turns out that cooking oils don't have an unlimited shelf life; they go bad.
This includes all edible oils like fish oil and oils that naturally occur in seeds and nuts (you ever notice how old nuts become dark and taste sour?).
Solid cooking fats like butter, lard, and coconut oil also go bad but, due to their chemical composition, don't spoil as quickly.
Eating rancid fat is a health hazard because the free radicals (oxidized particles) that it contains will damage cells in your body.
Your body has an antioxidant system as a defense against free radicals, but an overload places tremendous stress on it and reduces its effectiveness.
If you're planning to cook with a fat and want to know if it's gone bad, the simplest test is to smell it. If it smells like a crayon, it's rancid.
Oxidation (generation of free radicals) causes a fat to go rancid. Given enough time, all fats will oxidize due to entropy, but high temperatures, exposure to light, impurities (catalysts), and exposure to oxygen accelerate the process.
Certain fats oxidize faster than others. The more molecularly "saturated" a fat is, the more stable it is, and the longer it will stay fresh. Saturated fats have the longest shelf life, monounsaturated fats go bad faster, and polyunsaturated fats are the quickest to spoil.
To prevent your fats from spoiling, keep them in a cool, dark environment. However, don't be surprised if some are actually spoiled on the grocery store shelf; they've been sitting there a long time.
Types of Cooking Fats
All fats and oils are made of different saturated, monounsaturated, and polyunsaturated components. For example, coconut oil is extremely high in saturated fat, but also contains a bit of monounsaturated fat, and trace amounts of polyunsaturated fat.
Because they are molecularly saturated (fully bonded), saturated fats are the most shelf stable of all fats. For example, you don't even have to refrigerate ghee (clarified butter).
Some examples of highly saturated fats include butter, ghee, beef tallow, cocoa butter, coconut oil, palm kernel oil, and palm oil.
These spoil more quickly than saturated fat because the fatty acid chain is one particle short of being fully "saturated", so another particle can bond to that opening to create a free radical.
Lard, duck fat, chicken fat, peanut oil, canola (rapeseed) oil, olive oil, and shortening are a few examples of common monounsaturated fats. (Note that the oils listed here have are next highest in polyunsaturated fat, while the animal fats are next highest in saturated fat.)
These fats tend to spoil very quickly.
Because of their chemical composition (multiple particles are missing from the fat chain), these oxidize easily. The more PUFAs an oil contains, the faster it will go rancid.
Unfortunately, a majority of the standard fats on the grocery store shelves are polyunsaturated oils, and food manufacturers use these the most because they're relatively cheap.
Sources of high polyunsaturated fats (PUFAs) are soybean, sesame, cottonseed, sunflower, grapeseed, rice bran, corn, safflower, flaxseed, sesame, and walnut oils; anything that says "vegetable oil"; and margarine.
Assaulting your body with free radicals is harmful. Continuing the process day after day for a long period of time will eventually cause permanent damage.
I speculate that one of the main causes of modern disease (like cancer, Alzheimer's, arthritis, etc) is damage caused by free radicals found in high PUFA oils.
Years ago, these "vegetable oils" didn't exist. Most were invented once the falsified study on saturated fat causing heart disease became popular.
A majority of premade foods that we eat each day, especially those in the United States, are loaded with soybean, canola, corn, or sunflower oils. All of them are high in PUFAs, so they oxidize quickly if they've been sitting around. They may have even been rancid in production.
Also recall that high temperatures cause faster oxidation. Most restaurants fry foods in canola, soybean, and peanut oils, so these foods are more likely to contain higher concentrations of free radicals.
It's also worth mentioning that almost all salad dressings are just soybean oil with some spices and flavorings.
It's impossible to avoid them entirely because they're in almost everything, but to improve your health, I recommend avoiding as many vegetable oils as possible. Cocoa butter, palm oil, palm kernel oil, and coconut oil are okay since they're highly saturated. Animal fats are better.
Unrelated, if you take fish oil pills, and you find yourself belching up fish oil, they're rancid.