Discussion:
Error handling
Pedro Santos
2015-08-28 09:45:51 UTC
Permalink
Hello,

I'm having some troubles trying to issue a get that produces an error and
send it to an async channel. Here's what I have:

1 (defn- fetch-response
2 "Fetches the response as an async channel"
3 [url]
4 (try
5 (let [async-stream (http/get (str "http://" url)
{:connection-timeout 5000
6 :request-timeout
5000})
7 c (chan)]
8 (s/connect async-stream c)
9 c)
10 (catch Exception e
11 (print \E))))

I can't catch the exception. It says that the exception is on line 5, don't
know if it's async and I'm not doing this right.

Can someone help me?

Thanks.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Zach Tellman
2015-08-28 17:46:25 UTC
Permalink
`http/get` returns a deferred value, which will yield the full response.
Since a deferred value is *not* a stream, you can't connect it with
`manifold.stream/connect`. You could do `(d/chain rsp #(async/put! chan
%))` or something in that vein. In either case, I'm not sure why you
wouldn't be able to catch this exception, or how you'd know it was at line
5 if you hadn't caught it. If you can provide the stack trace, that might
help.
Post by Pedro Santos
Hello,
I'm having some troubles trying to issue a get that produces an error and
1 (defn- fetch-response
2 "Fetches the response as an async channel"
3 [url]
4 (try
5 (let [async-stream (http/get (str "http://" url)
{:connection-timeout 5000
6 :request-timeout
5000})
7 c (chan)]
8 (s/connect async-stream c)
9 c)
10 (catch Exception e
11 (print \E))))
I can't catch the exception. It says that the exception is on line 5,
don't know if it's async and I'm not doing this right.
Can someone help me?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Pedro Santos
2015-08-30 14:48:25 UTC
Permalink
Hey,

An example of that exception is here:
http://pastebin.com/skeVNzQA
This line:
scavenger.core$fetch_response.invoke(core.clj:45)
Is the http/get.

I ended up using d/on-realized and worked as I expected.
I'm still learning and I don't know if I'm doing something wrong. Do I have
to close the deferred in some way? I'm doing a program that does a LOT of
htt/get, and puts the responses on a channel. The program overflows and on
visualvm I can see that bytes and longs seam to be leaking. Here's the
offending stack trace:


​
Here's my example:
https://github.com/donbonifacio/scavenger/blob/master/src/scavenger/core.clj

Thanks,
Post by Zach Tellman
`http/get` returns a deferred value, which will yield the full response.
Since a deferred value is *not* a stream, you can't connect it with
`manifold.stream/connect`. You could do `(d/chain rsp #(async/put! chan
%))` or something in that vein. In either case, I'm not sure why you
wouldn't be able to catch this exception, or how you'd know it was at line
5 if you hadn't caught it. If you can provide the stack trace, that might
help.
Post by Pedro Santos
Hello,
I'm having some troubles trying to issue a get that produces an error and
1 (defn- fetch-response
2 "Fetches the response as an async channel"
3 [url]
4 (try
5 (let [async-stream (http/get (str "http://" url)
{:connection-timeout 5000
6
:request-timeout 5000})
7 c (chan)]
8 (s/connect async-stream c)
9 c)
10 (catch Exception e
11 (print \E))))
I can't catch the exception. It says that the exception is on line 5,
don't know if it's async and I'm not doing this right.
Can someone help me?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Pedro Santos
Home - http://psantos.zi-yu.com
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Zach Tellman
2015-09-11 04:41:43 UTC
Permalink
I'm sorry for the late response on this, I missed the second half of your
message. No, you don't need to do any resource management, but the
ArrayLongArrays are from Dirigiste statistics aggregators. Only having ~3k
of those isn't cause for concern.
Post by Pedro Santos
Hey,
http://pastebin.com/skeVNzQA
scavenger.core$fetch_response.invoke(core.clj:45)
Is the http/get.
I ended up using d/on-realized and worked as I expected.
I'm still learning and I don't know if I'm doing something wrong. Do I
have to close the deferred in some way? I'm doing a program that does a LOT
of htt/get, and puts the responses on a channel. The program overflows and
on visualvm I can see that bytes and longs seam to be leaking. Here's the
​
https://github.com/donbonifacio/scavenger/blob/master/src/scavenger/core.clj
Thanks,
Post by Zach Tellman
`http/get` returns a deferred value, which will yield the full response.
Since a deferred value is *not* a stream, you can't connect it with
`manifold.stream/connect`. You could do `(d/chain rsp #(async/put! chan
%))` or something in that vein. In either case, I'm not sure why you
wouldn't be able to catch this exception, or how you'd know it was at line
5 if you hadn't caught it. If you can provide the stack trace, that might
help.
Post by Pedro Santos
Hello,
I'm having some troubles trying to issue a get that produces an error
1 (defn- fetch-response
2 "Fetches the response as an async channel"
3 [url]
4 (try
5 (let [async-stream (http/get (str "http://" url)
{:connection-timeout 5000
6
:request-timeout 5000})
7 c (chan)]
8 (s/connect async-stream c)
9 c)
10 (catch Exception e
11 (print \E))))
I can't catch the exception. It says that the exception is on line 5,
don't know if it's async and I'm not doing this right.
Can someone help me?
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Pedro Santos
Home - http://psantos.zi-yu.com
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...