Hello!
On Sat, Aug 2, 2014 at 10:16 AM,
develephant.net wrote:
> First, thank you for adding the duplex socket support. Now that it is
> operational, should this code work now, if implemented correctly? Or is
> there a better way to achieve this?
>
The basic idea is correct. But your code contains various important
bugs due to the lack of proper error handling.
1. You should handle errors for all those IO calls like send_text()
and read_reply().
2. Also, if one of your light threads run into an unrecoverable error,
you should abort the whole request (with all the light threads) with
ngx.exit(444), for example.
3. And, be very careful about your "while true" loops. Ensure these
loops will never enter dead tight loops in some code paths (for
example, your loop in the "subscribe" thread will enter infinite tight
hot loop when read_reply() returns an error. Be very careful about the
termination conditions for these loops.
4. It's just wrong and inefficient to send ping in case your
recv_frame() call is timed out. You're not handling "pong"
specifically there anyway. Also, sending "ping" in your main thread
may conflict with the send_text() call in your user thread
(full-duplex cosockets only allow a reader and a writer operating on
the same socket, not two writers).
5. Better enable the connection pool for your redis connections (via
the set_keepalive call) in case of no errors.
Regards,
-agentzh