[BUG?] Should error pages be rendered if requesting an image?

I came across a problem when updating from rails3 to rails5, every time I request an image and the file is missing, the requests takes almost 2 seconds to finish because of the routes table taking too long to render (I have a project with +2600 routes).

If 5 or more images are missing, it takes so long that even some of them render this error:

Internal Server Error

could not obtain a connection from the pool within 5.000 seconds (waited 5.208 seconds); all pooled connections were in use