A mechanic at a San Jose, California rail yard has shot dead eight co-workers before taking his own life as police officers arrived on the scene.

The gunman, named by officials as 57-year-old Sam Cassidy, opened fire at around 6.30am local time at the light rail facility for the Valley Transportation Authority, which provides bus, light rail and other transit services throughout Santa Clara County, the most populated county in the San Francisco Bay Area.

Santa Clara County Sheriff Laurie Smith said Cassidy was still shooting when deputies arrived.

He told reporters: “When our deputies went through the door, initially he was still firing rounds. When our deputy saw him, he took his life.”

He said that officers “were going through hallways saying, ‘Sheriff’s office!’ He knew at that time that his time for firing shots was over”.

Apart from the eight dead, at least one other person is in hospital in a critical condition.

Investigators say that as yet they have not identified a motive for the shootings, but Cassidy’s ex-wife, Cecilia Nelms, told the Associated Press that he had a bad temper and would tell her that he wanted to kill people at work, “but I never believed him, and it never happened. Until now.”

More from US

She added that he had been treated for depression.

Cassidy had worked for Valley Transportation Authority since at least 2012, according to the public payroll and pension database known as Transparent California.

His position from 2012 to 2014 was listed as a mechanic. After that, he maintained substations, the records said.

This latest attack comes amid a rise in mass killings after the pandemic had closed many public places and kept people confined to their homes last year.

A database compiled by The Associated Press, USA Today and Northeastern University that tracks every mass killing over the last 15 years shows that the San Jose attack is the 15th mass killing so far in 2021, all of them shootings.

Eighty-six people have died in the shootings, compared with 106 for all of 2020. It is the sixth mass killing in a public place in 2021.

The database defines mass killings as four people dead, not including the shooter, meaning the overall toll of gun violence is much higher when adding in smaller incidents.

At the White House, President Joe Biden ordered flags to be flown at half-mast and urged Congress to act on legislation to curb gun violence.

“Every life that is taken by a bullet pierces the soul of our nation. We can, and we must, do more,” Biden said in a statement.