I recently had my crankshaft position sensor changed after having issues.
It started almost a month or so before I actually had it replaced. Once in a while trying to accelerate from a stop light or stop sign, I would have hard revving and what seemed to me as a misfire. I though this was due to fluids being old and dirty, so I had those changed first. It went away for a couple of days and proceeded to occur. I had stalled out while idling in a parking lot but thought nothing of it because I couldn't remember if I had shut the car off or not. The final straw came while accelerating from a stoplight. I had horrible acceleration, super hard revs, and even hear a loud clunk. As soon as this noise was made, my engine light started going crazy. The ESP light even light even came on. I barely made the drive to campus which was about three miles away. I pulled the codes and received P0335 and P0339. These both had to do with the crankshaft. I tried getting home but had no luck. About a mile down the road, I stalled out and lost everything. It took a good five minutes of cranks to get it started again. It ran long enough for me to get it back into a parking lot.
It turns out, the sensor is below the oil pan and what happens is, oil sometimes drips onto the sensor and saturates it. This causes problems with sending electrical signals back to the computer causing the failure.
I would've done the replacement myself but having skid plates and not the proper tools, I had it towed to the mechanic. It was a simple fix and only ran about $150 total for parts and labor.
After the new sensor was installed, it ran like a whole new beast. Now I did have a tune and after install it seemed to rev a little high. After a good hundred miles or so, it was right back to the correct rev level.
I just figured I would post my experience so that others can prevent the problem before they end up with a dead car on the side of the road.
Hope it helps!!