try (with-current-buffer (url-retrieve-synchronously "http://foo.bar" nil 't 1) (kill-buffer))
Documentation says:
(url-retrieve-synchronously URL &optional SILENT INHIBIT-COOKIES TIMEOUT)
...
"If TIMEOUT is passed, it should be a number that says (in seconds) how long to wait for a response before giving up."
Actually TIMEOUT is not working for me.
 
******
GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.18.9)