Improve timeout-related code for federation and URL previews. Contributed by @Jade