The crankshaft position sensor is a two-channel hall (magnetic blocking) effect center magnet/dual-transistor affair that detects two signals about the crankshaft's current position by reading (being blocked by) two sets of vanes on the backside of the main harmonic balancer (largest pulley at the bottom of the engine, accessible through the front passenger wheel-well).
There are two circular rows of metal "vanes" on the back of the balancer pulley, one with a single vane that functions as index position/tach signal and the other with six (x4) vanes that (more finely) indicate the precise timing of each of the six cylinders. A separate camshaft position sensor (facing into the sealed engine) picks up any lag or lead in the valve operations. This CPS sensor and pulley-vane affair replaces points and a distributor, directly reading the crankshaft with no gearing between it and the truth.
While they should and do last forever, the problem with the magnet and it's two Hall effect transistors is that the magnet is exposed to metallic brake dust and road grime through the thin air-gap between the plastic "foreign object shield" on the engine block and the back of the spinning (air sucking and blowing) balancer pulley, way down there right over the dusty road!
What happens is that over time, metal filings from brake rotors (and other people's brake rotors) find their way in there and lodge themselves on the center magnet, resulting in a magnetic filing shunt that greatly weakens the power of the magnet causing the Hall-effect transistors to be progressively more unable to get a good magnetic pulse. This problem gets far, far worse when the transistors are hotter, such as when the engine gets hot in summer, you use low octane fuel, the A/C or are in city driving. Occasionally wind conditions on the highway themselves can cause momentary failures as well. Hall effect transistors don't like heat and their sensitivity (even when new) drops markedly at high temperatures, so there is really nothing wrong with them - there's simply no more/enough "magnet" once it's covered in metal filings!
To add insult to injury these metal filings on the CPS center-magnet both blow (due to wind) and "move themselves" around (due to the movements of the metal vanes) causing it's magnetic field to seem to "move erratically" to the sensors, a set of conditions that result in a lot of erroneous ECM codes relating to bad ignition coil, bad ICM or bad spark plug/wiring codes where no problem actually exists. the computer has no way of knowing that it's own base-index and base-timing references are inaccurate, so it just assumes something further up the line is the issue.
In most cases the CPS simply needs to be removed and cleaned of metal filings on it's center magnet and all will be well again, but replacing it is also a good option, just keep your old one and clean it off for next time.
A good, more permanent solution (I have used and recommend) is to place a few very, very strong magnets (such as those rare earth neodymium or samarium cobalt magnets found in old hard drives) in a circle around the harmonic balancer on the outside of the lower engine block around it to trap brake dust before it gets into the pulley's back air gap. It's not a 100% solution but neither is the cheap plastic "foreign object shield" that lets this junk get sucked in there in the first place! Like the magnets that clean your ATF of metal bits in the tranny, it's simply an added layer of protection that will greatly increase your future mean-time between failures.
Keeping these four (or more) strong rare earth "air cleaner" magnets well-cleaned by wiping them off with a damp rag now and then will, likewise, maintain their ability to trap metal filings and dust before it gets sucked into the balancer-pulley's air gap, as a regular maintenance item.