FREE DIY temporary fix, Expensive 100% permanent fix.
This is what worked on our 2005 Chevrolet Suburban. Your truck may be similar.
In your engine bay, just inboard of the battery (toward the engine), there is a curvy plastic box with lots of big cables going to it. That is your engine computer (PCM). Pull off the plastic cover on the front, by the radiator (it only snaps on). It takes one small socket wrench (9/32″ I think) to unscrew the bolt holding the connectors to the computer. Pull the connector nearest the radiator. You will see blue plastic pieces on the connector. This is the blue connector. These blue pieces are clear so you can see the pins inside the connector. Look at the lower end of the connector. It will be full of corrosion. Mine looked like there was mud inside. Look in the mating connector on the Powertrain Control Module and see that it is also corroded inside. That is your problem.
The BEST fix is to replace the computer and wiring harness, which will set you back closer to $2000 than $0. The fix to get your truck running involves disassembling the connector and cleaning out the corrosion one pin at a time, as well as cleaning the connector on the computer. Open the computer itself and make sure it does not have water inside. If you don’t know how to deal with static-sensitive electronics, leave the opening of the computer to someone who does, or you risk an expensive computer-killing static shock!
The sequence of events:
First there was a check engine light, code P0332 (rear knock sensor). Then there was running like [deleted] and barely able to drive down the road, with a flashing check engine light. The transition took about 20 seconds from runs-great to runs-barely-and-smells-like-gasoline. Sometimes on a wet/rainy day when the truck seemed to be running well, the truck engine would die like you had turned off the ignition by removing the key (while driving down the road). This was unsatisfactory but it would always start right back up again. This was likely from shorting out the crank sensor.
Oh, and P.S. the radiator fans worked normally, except that after the truck was off. Anywhere from 11 seconds to maybe a couple of hours after the engine was stopped, the engine cooling fans would start turning at low speed until the battery was too depleted to turn the fans any longer. When the truck was put on another car’s jump-start cables the fans started turning within a minute. To prevent draining the battery totally, the free short-term fix was to pull the fans’ 40 amp fuse. This did nothing for the running-like-poo symptom, however.
The engine computer was setting codes P0300 (random misfire) and P0480 (fan control circuit). The bottom inch or two of the blue connector has wires for half the fuel injectors as well as the Crankshaft Position Sensor and the radiator fans. The conductive slurry of corrosion in the blue connector was cross-shorting out the whole mess.
Disassembling the blue connector was quite a job, and I literally went to a school to treat corrosion in electronics – do NOT be afraid to ask for help on this job from a good local electronics tech!
The P0332 was legit, and if you do a bit of web searching, you will find that GM issued a TSB for this problem. My rear knock sensor was stereotypically rusted and not-working, plus the knock sensor harness looked janky so I replaced that while I was in there, along with the other sensor. This requires removal of the intake manifold, so it is either an $800+ job or $40×2 for sensors, $50 for the harness, and if the intake manifold gasket is in good condition and you have the right chemicals and tools (including torque wrenches!) that’s all it costs to DIY.
The moral of this story: NEVER power-wash your engine bay. Ever. Power-washing puts water on top of the engine and rusts out the knock sensors, and power washing puts water in the PCM connectors. Wipe it off by hand, or leave it. It’s a truck, not a show car (unless it’s a show car, in which case trailer it!)