If anything, farming made societies more susceptible to famine. Specialization of labor and dependence on a specific plot of land made it much harder to simply move somewhere else when food was scarce. Hunter-gatherers and herders were almost always nomadic and moved to wherever food was available.
Finding food wasn't a constant struggle but when it happened it was an extinction event.
A farmer can rely on extra food created to sustain them in fallow years, and is much more stable than chasing deers around.