[racket] tcp-read handlers

From: Eduardo Bellani (ebellani at gmail.com)
Date: Sat Jan 18 16:53:04 EST 2014

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- From this code extracted from the context of where the exn took place,
this does seem to be the case:

;; url.rkt
(define (purify-http-port in-port)
  (define-values (in-pipe out-pipe) (make-pipe))
  (thread
   (λ ()
     (define status (http-read-status in-port))
     (define chunked? (http-read-headers in-port))
     (http-pipe-data chunked? in-port out-pipe)
     (close-input-port in-port)))
  in-pipe)

Thanks for the exn tip btw.

On 01/18/2014 02:04 PM, Matthew Flatt wrote:
> The `exn?` predicate would catch all exceptions from the base 
> libraries.[*]
> 
> I think the problem may be that the underlying TCP port is read in
> a separate decoding thread, and so the exception and printing
> happens in that thread. If I'm right, then that seems like a flaw
> in our implementation of decoding.
> 
> [*] To avoid interfering with the `exn:break?` exceptions triggered
> by Ctl-C, you almost always want `exn:fail?` instead of just
> `exn?`.
> 
> At Sat, 18 Jan 2014 09:50:15 -0200, Eduardo Bellani wrote: Is there
> a way to install a handler for the tcp-error exception? I have a
> function like this
> 
> (define (get-page link-url (max-tries 5)) (let loop ([current-try
> 0]) (with-handlers ([exn? (? (e) (if (> current-try max-tries) 
> (error 'get-page "failed because it exceeded ~a tries" max-tries) 
> (begin (sleep 2) (loop (add1 current-try)))))]) (get-pure-port
> link-url))))
> 
> that I'm using to crawl some data, but sometimes it's printing:
> 
> tcp-read: error reading system error: Connection reset by peer;
> errno=104 context...: /usr/racket/collects/net/url.rkt:392:3
> 
> Thanks for the attention.
> 
>> ____________________ Racket Users list: 
>> http://lists.racket-lang.org/users

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlLa98AACgkQSbLl0kCTjGnvEgCfcYCKhesckHi6R/FcBVmEpnGF
W/AAnj0B/5+KvsL7OIMSvG6mfS6bJU1d
=cAdF
-----END PGP SIGNATURE-----

Posted on the users mailing list.