The last month of summer brings a wave of fairs and festivals in Minnesota, the grand finale to a season of carnival rides, livestock contests and food on a stick.

For fair organizers and police, it also means heightened security procedures. With cities and counties drawing thousands of attendees to their anticipated once-a-year events, law enforcement and local officials have developed contingency plans for how to handle worst-case scenarios.

On Sunday, a 19-year-old gunman Northern California opened fire on the Gilroy Garlic Festival in northern California, killing three and injuring more than a dozen others. Police responded in minutes and fatally shot the gunman, according to the Associated Press.

Officers train and plan ahead for the possibility of crises situations like an active shooter, as well as smaller surprises such as traffic concerns or severe weather, said Sgt. Troy Greene, commander of the St. Paul Police Department’s Special Operations Unit.

“I think we’ve learned over time that the failure to plan is a plan to fail,” Greene said.

Before large public events in the Twin Cities area, police will generally conduct a risk assessment to anticipate problems or threats. Each local agency operates a bit differently, but all have the same priority: keeping the public safe.

Craig Samborski runs Festival of Sail Duluth, an event in the harbor featuring a parade of tall-masted ships that drew about a quarter-million visitors when it last came to the city in 2016. He said he has had roughly half a dozen meetings since January with representatives from the Coast Guard, the Duluth police and fire departments, the St. Louis County Sheriff and the Department of Natural Resources — all focused on developing an “incident action plan” ahead of the August festival.

“We take everything seriously,” said Samborski, who has been producing similar events around the country for years. “It’s designed to make the public feel safe and comfortable.”

A State Fair spokesperson said Minnesota’s famed get-together, which attracted more than 2 million people last summer, involves the coordination of federal, state and local agencies. More than 200 officers patrol the fair in uniforms and plain clothes, and visitors must go through a bag check at entry gates.

Though Gilroy Garlic Festival attendees were required to pass through metal detectors and have their bags searched, the California shooter snuck into the festival — an annual three-day attraction that draws more than 100,000 people to the small city hailed as the “Garlic Capital of the World” — by cutting through a fence. Police told the AP the tragedy could have been much worse had officers not been stationed throughout the fair and trained to respond to an active shooting.

Minnesota fair organizers and police would not explain the specifics of their security plans, but most involve the presence of law enforcement officers at festivals. Hopkins Police Sgt. Michael Glassberg said all the department’s officers were on duty for the city’s annual Raspberry Festival earlier this month.

“Hopkins is a very safe community, but it doesn’t mean we’re not always prepared,” he said.

Glassberg said families should designate a meet-up spot when heading to summer festivals in case people get separated during an emergency. Greene said fairgoers should use common sense and report suspicious activity to law enforcement. The federal government created a website with instructions for handling an active shooter situation.

“You have to live your life, but it’s like anything else,” Glassberg said. “If something were to happen, in that small chance, you need to be ready when you’re at an event.”