How can I prevent this from happening again
an outdated modem from 2019
Just pointing out you answered your own quesiton. If you know you’re on an old / unpatched / vulnerable router I would suggest getting one that is patched. There will always be things crawling the internet for exploits. Some just look but others may attempt stuff on home users.
Just my $0.02
That’s usually a sign of congestion.
Majority of home ISP users are on the download side.