My altima stalls randomly while idling, say at a stop or red light. I then have to wait a few minutes before it starts again. The starter is one year old and sounds good. My RPMs are very stready at ~750 RPMs while idling. At random, the engine will just shut off/stall. I have a check engine light on which is giving the knock sensor failure message. I have had this for about four years and have ignored it. Except for the stalling, the car runs great. If I give it gas, it will not stall. I replaced the distributor cap, rotor, plugs, wires, air filter, crank sensor (I had an error code for that) and cleaned the EGR valve. I noticed a small wear hole in the rectangular electronic's? box on the side of the MAF sensor. It is the small box with the harness plugged into it. However, I don't think a faulty MAF would cause the engine to just shut off the way my car does, considering that it idles smooth. When I unplug the MAF sensor, it idles rough so it seems to be doing its job. I think I am going to seal the small wear hole in this housing to keep moisture out. One other thing, the stalls do not start until after at least 10 to 15 minutes. Any thought on what else I can try?
Thanks!!!
One other thing, I let the car idle in my driveway today and it stopped running after about 15 minutes. It was idling smooth and then I heard a solenoid-like click and the car turned off. Once it has warmed up, it will stall every few minutes in the same way. The RPMs are at 750 and then there is an electronic click and the engine turns off. Any thoughts? When I tried it re-start it, I could not get ignition. I waited ten minutes and then it started fine again!!!

